From 3f9023281e1d8f9c8cc6ff5046719a4dbfbd03ad Mon Sep 17 00:00:00 2001 From: "roberto@oneiric64" Date: Fri, 20 Jan 2012 09:18:18 +0100 Subject: [PATCH] added --exec-pre-jail and --exec-post-jail --- lib/linux_ns.c | 16 ++++++++++++++++ uwsgi.c | 20 ++++++++++++++++++++ uwsgi.h | 4 ++++ 3 files changed, 40 insertions(+) diff --git a/lib/linux_ns.c b/lib/linux_ns.c index c1842c0c..361d72d4 100644 --- a/lib/linux_ns.c +++ b/lib/linux_ns.c @@ -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) { diff --git a/uwsgi.c b/uwsgi.c index 7e5a85ce..39f6fec9 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -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; diff --git a/uwsgi.h b/uwsgi.h index 6ca1c8e3..71944a42 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -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;