From 88be144a812eb910e6f6fa1b1933eb97d014ec9a Mon Sep 17 00:00:00 2001 From: "roberto@quantal64" Date: Tue, 10 Jul 2012 12:34:57 +0200 Subject: [PATCH] fixed a race condition in graceful reload --- core/emperor.c | 10 ++++++++++ core/master.c | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/core/emperor.c b/core/emperor.c index 065193c7..7353f69c 100644 --- a/core/emperor.c +++ b/core/emperor.c @@ -308,6 +308,15 @@ static void royal_death(int signum) { exit(0); } +static void emperor_massive_reload(int signum) { + struct uwsgi_instance *c_ui = ui->ui_next; + + while (c_ui) { + emperor_respawn(c_ui, uwsgi_now()); + c_ui = c_ui->ui_next; + } +} + void emperor_stats() { @@ -867,6 +876,7 @@ void emperor_loop() { uwsgi_unix_signal(SIGTERM, royal_death); uwsgi_unix_signal(SIGQUIT, royal_death); uwsgi_unix_signal(SIGUSR1, emperor_stats); + uwsgi_unix_signal(SIGHUP, emperor_massive_reload); memset(&ui_base, 0, sizeof(struct uwsgi_instance)); diff --git a/core/master.c b/core/master.c index afe926ba..a7dfbb20 100644 --- a/core/master.c +++ b/core/master.c @@ -13,6 +13,24 @@ void uwsgi_restore_auto_snapshot(int signum) { } +void uwsgi_block_signal(int signum) { + sigset_t smask; + sigemptyset(&smask); + sigaddset(&smask, signum); + if (sigprocmask(SIG_BLOCK, &smask, NULL)) { + uwsgi_error("sigprocmask()"); + } +} + +void uwsgi_unblock_signal(int signum) { + sigset_t smask; + sigemptyset(&smask); + sigaddset(&smask, signum); + if (sigprocmask(SIG_UNBLOCK, &smask, NULL)) { + uwsgi_error("sigprocmask()"); + } +} + #ifdef UWSGI_SNMP void uwsgi_master_manage_snmp(int snmp_fd) { struct sockaddr_in udp_client; @@ -94,7 +112,9 @@ void uwsgi_master_manage_emperor() { else if (byte == 1) { // un-lazy the stack to trigger a real reload uwsgi.lazy = 0; + uwsgi_block_signal(SIGHUP); grace_them_all(0); + uwsgi_unblock_signal(SIGHUP); } } else { @@ -1327,7 +1347,9 @@ health_cycle: char *touched = uwsgi_check_touches(uwsgi.touch_reload); if (touched) { uwsgi_log("*** %s has been touched... grace them all !!! ***\n", touched); + uwsgi_block_signal(SIGHUP); grace_them_all(0); + uwsgi_unblock_signal(SIGHUP); } }