fixed a race condition in graceful reload

This commit is contained in:
roberto@quantal64
2012-07-10 12:34:57 +02:00
parent 8046194696
commit 88be144a81
2 changed files with 32 additions and 0 deletions
+10
View File
@@ -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));
+22
View File
@@ -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);
}
}