diff --git a/include/vzerror.h b/include/vzerror.h index 00d1c47..9d665d2 100644 --- a/include/vzerror.h +++ b/include/vzerror.h @@ -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 --git a/src/lib/env.c b/src/lib/env.c index 7411504..e1beac4 100644 --- a/src/lib/env.c +++ b/src/lib/env.c @@ -547,12 +547,15 @@ int vps_start_custom(vps_handler *h, envid_t veid, vps_param *param, { 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")) @@ -561,6 +564,28 @@ int vps_start_custom(vps_handler *h, envid_t veid, vps_param *param, logger(-1, 0, "Container 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); @@ -663,6 +688,7 @@ err: close(wait_p[1]); close(err_p[0]); close(err_p[1]); + close(early_p); return ret; }