From: William Lallemand Date: Tue, 11 Sep 2018 08:06:23 +0000 (+0200) Subject: MEDIUM: startup: unify signal init between daemon and mworker mode X-Git-Tag: v1.9-dev2~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3801c1c2154a8229c5ea32e7575bc79d1c4c3ed;p=thirdparty%2Fhaproxy.git MEDIUM: startup: unify signal init between daemon and mworker mode The signals are now unblocked only once the configuration have been parsed. --- diff --git a/include/proto/signal.h b/include/proto/signal.h index 063683f4e2..b61a52725d 100644 --- a/include/proto/signal.h +++ b/include/proto/signal.h @@ -32,6 +32,7 @@ struct sig_handler *signal_register_fct(int sig, void (*fct)(struct sig_handler struct sig_handler *signal_register_task(int sig, struct task *task, int reason); void signal_unregister_handler(struct sig_handler *handler); void signal_unregister_target(int sig, void *target); +void haproxy_unblock_signals(); static inline void signal_process_queue() { diff --git a/src/haproxy.c b/src/haproxy.c index e2fd627f8e..1fa1d3cd77 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -497,14 +497,7 @@ static void mworker_block_signals() static void mworker_unblock_signals() { - sigset_t set; - - sigemptyset(&set); - sigaddset(&set, SIGUSR1); - sigaddset(&set, SIGUSR2); - sigaddset(&set, SIGHUP); - sigaddset(&set, SIGCHLD); - ha_sigmask(SIG_UNBLOCK, &set, NULL); + haproxy_unblock_signals(); } /* @@ -3040,7 +3033,7 @@ int main(int argc, char **argv) #endif /* !USE_CPU_AFFINITY */ /* when multithreading we need to let only the thread 0 handle the signals */ - pthread_sigmask(SIG_SETMASK, &old_sig, NULL); + haproxy_unblock_signals(); /* Finally, start the poll loop for the first thread */ run_thread_poll_loop(&tids[0]); @@ -3057,7 +3050,7 @@ int main(int argc, char **argv) #endif } #else /* ! USE_THREAD */ - + haproxy_unblock_signals(); run_thread_poll_loop((int []){0}); #endif diff --git a/src/signal.c b/src/signal.c index 6f74a6f46f..75d5c65a3a 100644 --- a/src/signal.c +++ b/src/signal.c @@ -109,19 +109,6 @@ int signal_init() memset(signal_queue, 0, sizeof(signal_queue)); memset(signal_state, 0, sizeof(signal_state)); - /* Ensure signals are not blocked. Some shells or service managers may - * accidently block all of our signals unfortunately, causing lots of - * zombie processes to remain in the background during reloads. - */ - sigemptyset(&blocked_sig); - /* Ensure that SIGUSR2 is blocked until the end of configuration - * parsing We don't want the process to be killed by an unregistered - * USR2 signal when the master-worker is reloading */ - sigaddset(&blocked_sig, SIGUSR2); - sigaddset(&blocked_sig, SIGCHLD); - - ha_sigmask(SIG_SETMASK, &blocked_sig, NULL); - sigfillset(&blocked_sig); sigdelset(&blocked_sig, SIGPROF); /* man sigprocmask: If SIGBUS, SIGFPE, SIGILL, or SIGSEGV are @@ -139,6 +126,21 @@ int signal_init() return pool_head_sig_handlers != NULL; } +/* + * This function should be called to unblock all signals + */ +void haproxy_unblock_signals() +{ + sigset_t set; + + /* Ensure signals are not blocked. Some shells or service managers may + * accidently block all of our signals unfortunately, causing lots of + * zombie processes to remain in the background during reloads. + */ + sigemptyset(&set); + ha_sigmask(SIG_SETMASK, &set, NULL); +} + /* releases all registered signal handlers */ void deinit_signals() {