From fc6f125d17d00e589aaeabecbd2aa5249c01c949 Mon Sep 17 00:00:00 2001 From: Unbit Date: Mon, 11 Aug 2014 10:14:49 +0200 Subject: [PATCH] added hook_as_emperor_setns --- core/hooks.c | 16 +++++++++++++++- core/uwsgi.c | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/hooks.c b/core/hooks.c index d4e53b25..0ad8d89d 100644 --- a/core/hooks.c +++ b/core/hooks.c @@ -748,8 +748,22 @@ void uwsgi_hooks_setns_run(struct uwsgi_string_list *l, pid_t pid, uid_t uid, gi } // now run the action and then exit - exit(0); + action++; + char *colon = strchr(action, ':'); + if (!colon) { + uwsgi_log("invalid hook syntax must be action:arg\n"); + exit(1); + } + *colon = 0; + struct uwsgi_hook *uh = uwsgi_hook_by_name(action); + if (!uh) { + uwsgi_log("hook action not found: %s\n", action); + exit(1); + } + *colon = ':'; + uwsgi_log("running \"%s\" (setns)...\n", usl->value); + exit(uh->func(colon+1)); } else { uwsgi_error("uwsgi_hooks_setns_run()/fork()"); diff --git a/core/uwsgi.c b/core/uwsgi.c index ac6173de..ae9d2f83 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -425,6 +425,8 @@ static struct uwsgi_option uwsgi_base_options[] = { {"hook-as-emperor-before-vassal", required_argument, 0, "run the specified hook before the new vassal is spawned", uwsgi_opt_add_string_list, &uwsgi.hook_as_emperor_before_vassal, 0}, {"hook-as-vassal-before-drop", required_argument, 0, "run the specified hook into vassal, before dropping its privileges", uwsgi_opt_add_string_list, &uwsgi.hook_as_vassal_before_drop, 0}, + {"hook-as-emperor-setns", required_argument, 0, "run the specified hook in the emperor entering vassal namespace", uwsgi_opt_add_string_list, &uwsgi.hook_as_emperor_setns, 0}, + {"hook-as-mule", required_argument, 0, "run the specified hook in each mule", uwsgi_opt_add_string_list, &uwsgi.hook_as_mule, 0}, {"hook-as-gateway", required_argument, 0, "run the specified hook in each gateway", uwsgi_opt_add_string_list, &uwsgi.hook_as_gateway, 0},