added --exec-pre-jail and --exec-post-jail

This commit is contained in:
roberto@oneiric64
2012-01-20 09:18:18 +01:00
parent 4e21fe6607
commit 3f9023281e
3 changed files with 40 additions and 0 deletions
+16
View File
@@ -33,6 +33,22 @@ void linux_namespace_start(void *argv) {
uwsgi_error("clone()");
exit(1);
}
// run the post-jail scripts
if (setenv("UWSGI_JAIL_PID", uwsgi_num2str((int) pid), 1)) {
uwsgi_error("setenv()");
}
struct uwsgi_string_list *usl = uwsgi.exec_post_jail;
while(usl) {
uwsgi_log("running \"%s\" (post-jail)...\n", usl->value);
int ret = uwsgi_run_command_and_wait(NULL, usl->value);
if (ret != 0) {
uwsgi_log("command \"%s\" exited with non-zero code: %d\n", usl->value, ret);
exit(1);
}
usl = usl->next;
}
uwsgi_log("waiting for jailed master (pid: %d) death...\n", (int) pid);
pid = waitpid(pid, &waitpid_status, 0);
if (pid < 0) {
+20
View File
@@ -153,6 +153,8 @@ static struct option long_base_options[] = {
#ifdef __linux__
{"unshare", required_argument,0, LONG_ARGS_UNSHARE},
#endif
{"exec-pre-jail", required_argument,0, LONG_ARGS_EXEC_PRE_JAIL},
{"exec-post-jail", required_argument,0, LONG_ARGS_EXEC_POST_JAIL},
{"exec-as-root", required_argument,0, LONG_ARGS_EXEC_AS_ROOT},
{"exec-as-user", required_argument,0, LONG_ARGS_EXEC_AS_USER},
#ifdef UWSGI_INI
@@ -1724,6 +1726,18 @@ int main(int argc, char *argv[], char *envp[]) {
}
}
// run the pre-jail scripts
struct uwsgi_string_list *usl = uwsgi.exec_pre_jail;
while(usl) {
uwsgi_log("running \"%s\" (pre-jail)...\n", usl->value);
int ret = uwsgi_run_command_and_wait(NULL, usl->value);
if (ret != 0) {
uwsgi_log("command \"%s\" exited with non-zero code: %d\n", usl->value, ret);
exit(1);
}
usl = usl->next;
}
// call jail systems
for (i = 0; i < uwsgi.gp_cnt; i++) {
@@ -3594,6 +3608,12 @@ static int manage_base_opt(int i, char *optarg) {
uwsgi_string_new_list(&uwsgi.touch_reload, optarg);
uwsgi.master_process = 1;
return 1;
case LONG_ARGS_EXEC_PRE_JAIL:
uwsgi_string_new_list(&uwsgi.exec_pre_jail, optarg);
return 1;
case LONG_ARGS_EXEC_POST_JAIL:
uwsgi_string_new_list(&uwsgi.exec_post_jail, optarg);
return 1;
case LONG_ARGS_EXEC_AS_ROOT:
uwsgi_string_new_list(&uwsgi.exec_as_root, optarg);
return 1;
+4
View File
@@ -560,6 +560,8 @@ struct uwsgi_opt {
#define LONG_ARGS_LOGGER 17172
#define LONG_ARGS_STATIC_INDEX 17173
#define LONG_ARGS_CHEAPER_STEP 17174
#define LONG_ARGS_EXEC_PRE_JAIL 17175
#define LONG_ARGS_EXEC_POST_JAIL 17176
#define UWSGI_OK 0
@@ -1229,6 +1231,8 @@ struct uwsgi_server {
struct uwsgi_probe *probes;
struct uwsgi_string_list *exec_pre_jail;
struct uwsgi_string_list *exec_post_jail;
struct uwsgi_string_list *exec_as_root;
struct uwsgi_string_list *exec_as_user;