]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: systemd: ensure we don't miss signals
authorWilly Tarreau <w@1wt.eu>
Sat, 27 Feb 2016 06:58:50 +0000 (07:58 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 27 Feb 2016 07:28:42 +0000 (08:28 +0100)
There's a race condition in the systemd wrapper. People who restart it
too fast report old processes remaining there. Here if the signal is
caught before entering the "while" loop we block indefinitely on the
wait() call. Let's check the caught signal before calling wait(). It
doesn't completely close the race, a window still exists between the
test of the flag and the call to wait(), but it's much smaller. A
safer solution could involve pselect() to wait for the signal
delivery.

src/haproxy-systemd-wrapper.c

index e588af931ce5aa694784ea82ad326d8fae9869c6..10396aec85482b0f22d8e8c9bb9161c157fb397e 100644 (file)
@@ -197,7 +197,7 @@ int main(int argc, char **argv)
        }
 
        status = -1;
-       while (-1 != wait(&status) || errno == EINTR) {
+       while (caught_signal || wait(&status) != -1 || errno == EINTR) {
                if (caught_signal == SIGUSR2 || caught_signal == SIGHUP) {
                        caught_signal = 0;
                        do_restart();