From bcf1f46d339f3abf64698e9d897b1bf011ebf090 Mon Sep 17 00:00:00 2001 From: Unbit Date: Thu, 28 Aug 2014 18:09:02 +0200 Subject: [PATCH] added vassal's plugin hooks --- core/emperor.c | 27 ++++++++++++++++++++++++++- uwsgi.h | 6 ++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/core/emperor.c b/core/emperor.c index adc20c87..3cfc3593 100644 --- a/core/emperor.c +++ b/core/emperor.c @@ -1093,7 +1093,20 @@ int uwsgi_emperor_vassal_start(struct uwsgi_instance *n_ui) { } static void uwsgi_emperor_spawn_vassal(struct uwsgi_instance *n_ui) { + int i; + // run plugin hooks for the vassal + for (i = 0; i < 256; i++) { + if (uwsgi.p[i]->vassal) { + uwsgi.p[i]->vassal(n_ui); + } + } + + for (i = 0; i < uwsgi.gp_cnt; i++) { + if (uwsgi.gp[i]->vassal) { + uwsgi.gp[i]->vassal(n_ui); + } + } #ifdef __linux__ if (prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0)) { @@ -1350,7 +1363,6 @@ static void uwsgi_emperor_spawn_vassal(struct uwsgi_instance *n_ui) { } // close all of the unneded fd - int i; for (i = 3; i < (int) uwsgi.max_fd; i++) { if (uwsgi_fd_is_safe(i)) continue; @@ -1429,6 +1441,19 @@ static void uwsgi_emperor_spawn_vassal(struct uwsgi_instance *n_ui) { func(n_ui->name, n_ui->uid, n_ui->gid); } + // ->vassal_before_exec + for (i = 0; i < 256; i++) { + if (uwsgi.p[i]->vassal_before_exec) { + uwsgi.p[i]->vassal_before_exec(n_ui); + } + } + + for (i = 0; i < uwsgi.gp_cnt; i++) { + if (uwsgi.gp[i]->vassal) { + uwsgi.gp[i]->vassal_before_exec(n_ui); + } + } + // start !!! if (execvp(vassal_argv[0], vassal_argv)) { uwsgi_error("execvp()"); diff --git a/uwsgi.h b/uwsgi.h index 3c7f6f1f..29354bba 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -6,6 +6,8 @@ extern "C" { #endif +#define UWSGI_PLUGIN_API 1 + #define UMAX16 65536 #define UMAX8 256 @@ -1000,6 +1002,7 @@ struct uwsgi_protocol { }; struct uwsgi_server; +struct uwsgi_instance; struct uwsgi_plugin { @@ -1058,6 +1061,9 @@ struct uwsgi_plugin { struct uwsgi_buffer* (*exception_msg)(struct wsgi_request *); struct uwsgi_buffer* (*exception_repr)(struct wsgi_request *); void (*exception_log)(struct wsgi_request *); + + void (*vassal)(struct uwsgi_instance *); + void (*vassal_before_exec)(struct uwsgi_instance *); }; #ifdef UWSGI_PCRE