BUG/MINOR: signals/poller: set the poller timeout to 0 when there are signals

When receiving a signal before entering the poller, and without any
activity in the process, the poller will be entered with a timeout
calculated without checking the signals.

Since commit 4f59d3 ("MINOR: time: increase the minimum wakeup interval
to 60s") the issue is much more visible because it could be stuck for
60s.

When in mworker mode, if a worker quits and the SIGCHLD signal deliver
at the right time to the master, this one could be stuck for the time of
the timeout.

This should fix issue #1841

Must be backported in every stable version.

(cherry picked from commit 43c891dda0c7c1c9f12dab5b77ac20b158a68adc)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 96aaeb5fc3b81a58a38b5371e8c340ce0b50e5eb)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 2baf3f8d1122ec18bd09bcc9af4800e23e9997f5)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/ev_epoll.c b/src/ev_epoll.c
index 330c38c..36fdc3a 100644
--- a/src/ev_epoll.c
+++ b/src/ev_epoll.c
@@ -185,8 +185,10 @@
 
 	thread_harmless_now();
 
-	/* now let's wait for polled events */
-	wait_time = wake ? 0 : compute_poll_timeout(exp);
+	/* Now let's wait for polled events.
+	 * Check if the signal queue is not empty in case we received a signal
+	 * before entering the loop, so we don't wait MAX_DELAY_MS for nothing */
+	wait_time = (wake | signal_queue_len) ? 0 : compute_poll_timeout(exp);
 	tv_entering_poll();
 	activity_count_runtime();
 	do {
diff --git a/src/ev_evports.c b/src/ev_evports.c
index 109e59c..e80b9c2 100644
--- a/src/ev_evports.c
+++ b/src/ev_evports.c
@@ -153,10 +153,10 @@
 
 	thread_harmless_now();
 
-	/*
-	 * Determine how long to wait for events to materialise on the port.
-	 */
-	wait_time = wake ? 0 : compute_poll_timeout(exp);
+	/* Now let's wait for polled events.
+	 * Check if the signal queue is not empty in case we received a signal
+	 * before entering the loop, so we don't wait MAX_DELAY_MS for nothing */
+	wait_time = (wake | signal_queue_len) ? 0 : compute_poll_timeout(exp);
 	tv_entering_poll();
 	activity_count_runtime();
 
diff --git a/src/ev_kqueue.c b/src/ev_kqueue.c
index d51a833..db7c9cd 100644
--- a/src/ev_kqueue.c
+++ b/src/ev_kqueue.c
@@ -141,8 +141,10 @@
 	}
 	fd_nbupdt = 0;
 
-	/* now let's wait for events */
-	wait_time = wake ? 0 : compute_poll_timeout(exp);
+	/* Now let's wait for polled events.
+	 * Check if the signal queue is not empty in case we received a signal
+	 * before entering the loop, so we don't wait MAX_DELAY_MS for nothing */
+	wait_time = (wake | signal_queue_len) ? 0 : compute_poll_timeout(exp);
 	fd = global.tune.maxpollevents;
 	tv_entering_poll();
 	activity_count_runtime();
diff --git a/src/ev_poll.c b/src/ev_poll.c
index c30aadb..da675eb 100644
--- a/src/ev_poll.c
+++ b/src/ev_poll.c
@@ -21,6 +21,7 @@
 #include <haproxy/api.h>
 #include <haproxy/fd.h>
 #include <haproxy/global.h>
+#include <haproxy/signal.h>
 #include <haproxy/ticks.h>
 #include <haproxy/time.h>
 
@@ -198,8 +199,10 @@
 		}
 	}
 
-	/* now let's wait for events */
-	wait_time = wake ? 0 : compute_poll_timeout(exp);
+	/* Now let's wait for polled events.
+	 * Check if the signal queue is not empty in case we received a signal
+	 * before entering the loop, so we don't wait MAX_DELAY_MS for nothing */
+	wait_time = (wake | signal_queue_len) ? 0 : compute_poll_timeout(exp);
 	tv_entering_poll();
 	activity_count_runtime();
 	status = poll(poll_events, nbfd, wait_time);