]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: mworker: properly pass SIGTTOU/SIGTTIN to workers
authorWilly Tarreau <w@1wt.eu>
Wed, 11 Dec 2019 13:24:07 +0000 (14:24 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 11 Dec 2019 13:26:53 +0000 (14:26 +0100)
If a new process is started with -sf and it fails to bind, it may send
a SIGTTOU to the master process in hope that it will temporarily unbind.
Unfortunately this one doesn't catch it and stops to background instead
of forwarding the signal to the workers. The same is true for SIGTTIN.

This commit simply implements an extra signal handler for the master to
deal with such signals that must be passed down to the workers. It must
be backported as far as 1.8, though there the code differs in that it's
entirely in haproxy.c and doesn't require an extra sig handler.

include/proto/mworker.h
src/haproxy.c
src/mworker.c

index 04187826665d74c6c79e1c810778fd0ec8b97add..595cc195061fe795405423f1d70380ab7e27b043 100644 (file)
@@ -22,6 +22,7 @@ void mworker_env_to_proc_list();
 void mworker_block_signals();
 void mworker_unblock_signals();
 
+void mworker_broadcast_signal(struct sig_handler *sh);
 void mworker_catch_sighup(struct sig_handler *sh);
 void mworker_catch_sigterm(struct sig_handler *sh);
 void mworker_catch_sigchld(struct sig_handler *sh);
index 4e4a7deb719f41602376f7fb2be9fa29c5330fe2..a7f6a247dd3633fe525989a25e4519dd34642ce7 100644 (file)
@@ -847,12 +847,16 @@ static void mworker_loop()
 
        master = 1;
 
+       signal_unregister(SIGTTIN);
+       signal_unregister(SIGTTOU);
        signal_unregister(SIGUSR1);
        signal_unregister(SIGHUP);
        signal_unregister(SIGQUIT);
 
        signal_register_fct(SIGTERM, mworker_catch_sigterm, SIGTERM);
        signal_register_fct(SIGUSR1, mworker_catch_sigterm, SIGUSR1);
+       signal_register_fct(SIGTTIN, mworker_broadcast_signal, SIGTTIN);
+       signal_register_fct(SIGTTOU, mworker_broadcast_signal, SIGTTOU);
        signal_register_fct(SIGINT, mworker_catch_sigterm, SIGINT);
        signal_register_fct(SIGHUP, mworker_catch_sighup, SIGHUP);
        signal_register_fct(SIGUSR2, mworker_catch_sighup, SIGUSR2);
index 511d9617dc41fe89053a6e4500e8aaeec015e402..ff3e16b8fb5c19b4143a8534a49c5573836dcbe2 100644 (file)
@@ -204,6 +204,8 @@ void mworker_block_signals()
        sigemptyset(&set);
        sigaddset(&set, SIGUSR1);
        sigaddset(&set, SIGUSR2);
+       sigaddset(&set, SIGTTIN);
+       sigaddset(&set, SIGTTOU);
        sigaddset(&set, SIGHUP);
        sigaddset(&set, SIGCHLD);
        ha_sigmask(SIG_SETMASK, &set, NULL);
@@ -216,6 +218,12 @@ void mworker_unblock_signals()
 
 /* ----- mworker signal handlers ----- */
 
+/* broadcast the configured signal to the workers */
+void mworker_broadcast_signal(struct sig_handler *sh)
+{
+       mworker_kill(sh->arg);
+}
+
 /*
  * When called, this function reexec haproxy with -sf followed by current
  * children PIDs and possibly old children PIDs if they didn't leave yet.