diff --git a/core/emperor.c b/core/emperor.c index abbccf71..f36eca10 100644 --- a/core/emperor.c +++ b/core/emperor.c @@ -1226,8 +1226,10 @@ int uwsgi_emperor_vassal_start(struct uwsgi_instance *n_ui) { uwsgi.emperor_broodlord_num++; } - // TODO pre-start hook + if (uwsgi_hooks_run_and_return(uwsgi.hook_as_emperor_before_vassal, "as-emperor-before-vassal", NULL, 0)) { + emperor_del(n_ui); + } // check for fork server char *fork_server = uwsgi.emperor_use_fork_server; @@ -1371,6 +1373,8 @@ static void uwsgi_emperor_spawn_vassal(struct uwsgi_instance *n_ui) { } #endif + uwsgi_hooks_run(uwsgi.hook_as_vassal_before_drop, "as-vassal-before-drop", 1); + #ifdef UWSGI_CAP #if defined(CAP_LAST_CAP) && defined(PR_CAPBSET_READ) && defined(PR_CAPBSET_DROP) if (uwsgi.emperor_cap && uwsgi.emperor_cap_count > 0) { diff --git a/core/uwsgi.c b/core/uwsgi.c index 6529ed90..3df6b24c 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -422,6 +422,9 @@ static struct uwsgi_option uwsgi_base_options[] = { {"hook-as-on-demand-vassal", required_argument, 0, "run the specified hook whenever a vassal enters on-demand mode", uwsgi_opt_add_string_list, &uwsgi.hook_as_on_demand_vassal, 0}, + {"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-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}, diff --git a/uwsgi.h b/uwsgi.h index f537eafd..f7b68b4a 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2741,6 +2741,8 @@ struct uwsgi_server { char *emperor_chdir_attr; struct uwsgi_string_list *subscription_algos; int subscription_mountpoints; + struct uwsgi_string_list *hook_as_emperor_before_vassal; + struct uwsgi_string_list *hook_as_vassal_before_drop; }; struct uwsgi_rpc {