diff --git a/master.c b/master.c index 009e908c..0388bedf 100644 --- a/master.c +++ b/master.c @@ -1374,6 +1374,15 @@ healthy: } } } +#ifdef UWSGI_SPOOLER + if (uwsgi.shared->spooler_pid > 0 && uwsgi.shared->spooler_harakiri > 0) { + if (uwsgi.shared->spooler_harakiri < (time_t) uwsgi.current_time) { + uwsgi_log("*** HARAKIRI ON THE SPOOLER (pid: %d) ***\n", uwsgi.shared->spooler_pid); + kill(uwsgi.shared->spooler_pid, SIGKILL); + uwsgi.shared->spooler_harakiri = 0; + } + } +#endif #ifdef UWSGI_UDP // check for cluster nodes diff --git a/signal.c b/signal.c index 91e0c51a..6926c374 100644 --- a/signal.c +++ b/signal.c @@ -30,6 +30,13 @@ int uwsgi_signal_handler(uint8_t sig) { set_mule_harakiri(uwsgi.shared->options[UWSGI_OPTION_MULE_HARAKIRI]); } } +#ifdef UWSGI_SPOOLER + else if (uwsgi.spool_dir && uwsgi.shared->spooler_pid > 0 && (getpid() == uwsgi.shared->spooler_pid)) { + if(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) { + set_spooler_harakiri(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI]); + } + } +#endif int ret = uwsgi.p[use->modifier1]->signal_handler(sig, use->handler); @@ -39,12 +46,19 @@ int uwsgi_signal_handler(uint8_t sig) { set_harakiri(0); } } - if (uwsgi.muleid > 0) { + else if (uwsgi.muleid > 0) { uwsgi.mules[uwsgi.muleid-1].sig = 0; if(uwsgi.mules[uwsgi.muleid-1].harakiri > 0) { set_mule_harakiri(0); } } +#ifdef UWSGI_SPOOLER + else if (uwsgi.spool_dir && uwsgi.shared->spooler_pid > 0 && (getpid() == uwsgi.shared->spooler_pid)) { + if(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) { + set_spooler_harakiri(0); + } + } +#endif return ret; } diff --git a/spooler.c b/spooler.c index 7f766492..9a36b028 100644 --- a/spooler.c +++ b/spooler.c @@ -413,7 +413,13 @@ void spooler_manage_task(char *dir, char *task) { for(i=0;i<0xff;i++) { if (uwsgi.p[i]->spooler) { time_t now = time(NULL); + if(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) { + set_spooler_harakiri(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI]); + } ret = uwsgi.p[i]->spooler(task, spool_buf, uh.pktsize, body, body_len); + if(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) { + set_spooler_harakiri(0); + } if (body) { free(body); } diff --git a/utils.c b/utils.c index 2d3d9149..5a1fc5b1 100644 --- a/utils.c +++ b/utils.c @@ -121,6 +121,18 @@ void set_mule_harakiri(int sec) { } } +void set_spooler_harakiri(int sec) { + if (sec == 0) { + uwsgi.shared->spooler_harakiri = 0; + } + else { + uwsgi.shared->spooler_harakiri = time(NULL) + sec; + } + if (!uwsgi.master_process) { + alarm(sec); + } +} + void daemonize(char *logfile) { pid_t pid; diff --git a/uwsgi.h b/uwsgi.h index 87fb6cb9..dd959c53 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1609,6 +1609,7 @@ struct uwsgi_shared { #ifdef UWSGI_SPOOLER pid_t spooler_pid; int spooler_frequency; + time_t spooler_harakiri; #endif #ifdef UWSGI_SNMP @@ -1803,6 +1804,7 @@ pid_t spooler_start(void); void set_harakiri(int); void set_mule_harakiri(int); +void set_spooler_harakiri(int); void inc_harakiri(int); #ifdef __BIG_ENDIAN__