Hi,
>> I didn't do C for a while, so I'm not sure I'll be able to do
>> something simple and safe.
>>
>> I'm available to compile and test this until the openvz server should
>> be production at the end of next week... but I'll take the time to do
>> all the test we need before.
>>
>> If some can help me on this issue.
>
> I have patched env.c to be able to execute a script before starting a VE
>
> I don't know if it is the best way to do that, but it work for what I need
I had no feed back on this patch, is it will be applied ? or maybe nobody
need this but me ?
I don't know if it'is possible to do this better, or add a better security
check, but as I said in my first mail, I don't developed in C for a while
thanks
Yoann
diff -r -u a/vzctl-3.0.22/include/vzerror.h b/vzctl-3.0.22/include/vzerror.h
--- a/vzctl-3.0.22/include/vzerror.h 2007-12-17 14:44:21.000000000 +0100
+++ b/vzctl-3.0.22/include/vzerror.h 2008-01-08 12:53:25.000000000 +0100
@@ -63,7 +63,7 @@
#define VZ_CANT_ADDIP 34
#define VZ_VALIDATE_ERROR 35
#define VZ_OVERCOMMIT_ERROR 36
-
+#define VZ_EARLY_SCRIPT_ERROR 37
/****************************
Filesystem errros
****************************/
diff -r -u a/vzctl-3.0.22/src/lib/env.c b/vzctl-3.0.22/src/lib/env.c
--- a/vzctl-3.0.22/src/lib/env.c 2007-12-17 14:44:21.000000000 +0100
+++ b/vzctl-3.0.22/src/lib/env.c 2008-01-08 17:18:14.786271752 +0100
@@ -545,12 +545,15 @@
{
int wait_p[2];
int err_p[2];
- int ret, err;
+ int ret, err,early_p;
char buf[64];
char *dist_name;
struct sigaction act;
+ char *command;
+ char *early_script;
vps_res *res = ¶m->res;
dist_actions actions;
+ early_script = strdup("/etc/vz/early_script.sh");
memset(&actions, 0, sizeof(actions));
if (check_var(res->fs.root, "VE_ROOT is not set"))
@@ -559,6 +562,28 @@
logger(-1, 0, "VE is already running");
return VZ_VE_RUNNING;
}
+
+ if (early_script == NULL) {
+ logger(-1,0,"memory allocation error for early_script");
+ return VZ_EARLY_SCRIPT_ERROR;
+ }
+
+ early_p = open(early_script,O_RDONLY);
+ if ( early_p != -1 ) {
+ logger(0, 0, "early_script.sh started");
+ command = (char*)malloc(3+strlen(early_script)+1+10);
+ sprintf(command,"sh %s %d",early_script,veid);
+ if ( system(command) == 0 ) {
+ logger(0, 0, "early_script.sh finished");
+ } else {
+ logger(-1, 0, "early_script.sh failed");
+ return VZ_EARLY_SCRIPT_ERROR;
+ }
+ free(command);
+ } else {
+ logger(0, 0, "early_script.sh does not exist or is not readable ");
+ }
+
if ((ret = check_ub(&res->ub)))
return ret;
dist_name = get_dist_name(&res->tmpl);
@@ -661,6 +686,7 @@
close(wait_p[1]);
close(err_p[0]);
close(err_p[1]);
+ close(early_p);
return ret;
}