MEDIUM: startup: unify signal init between daemon and mworker mode

The signals are now unblocked only once the configuration have been
parsed.
This commit is contained in:
William Lallemand 2018-09-11 10:06:23 +02:00 committed by Willy Tarreau
parent 242aae96c7
commit d3801c1c21
3 changed files with 19 additions and 23 deletions

View File

@ -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()
{

View File

@ -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

View File

@ -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()
{