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 063683f..b61a527 100644
--- a/include/proto/signal.h
+++ b/include/proto/signal.h
@@ -32,6 +32,7 @@
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 e2fd627..1fa1d3c 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -497,14 +497,7 @@
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 @@
#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 @@
#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 6f74a6f..75d5c65 100644
--- a/src/signal.c
+++ b/src/signal.c
@@ -109,19 +109,6 @@
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 @@
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()
{