From da4ccb18f4c6900c6e5ad39e226cab9699837412 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 1 Feb 2021 11:36:31 -0500 Subject: Check signals first in the loop Signals need to be checked first in the loop to catch any that were delivered between setting up the signals handlers and entering the loop, i.e. in the time it takes to initially start each of the services. --- daemon.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/daemon.c b/daemon.c index cf7f805..59215f6 100644 --- a/daemon.c +++ b/daemon.c @@ -321,6 +321,31 @@ int main(int argc, char *argv[]) { sigset_t mask; sigemptyset(&mask); for (;;) { + if (signals[SIGCHLD]) { + int status; + pid_t pid; + while (0 < (pid = waitpid(-1, &status, WNOHANG))) { + serviceReap(pid, status); + } + if (pid < 0 && errno != ECHILD) syslog(LOG_WARNING, "waitpid: %m"); + setTitle(); + signals[SIGCHLD] = 0; + } + + if (signals[SIGINT] || signals[SIGTERM]) { + break; + } + if (signals[SIGHUP]) { + parseConfig(configPath); + setTitle(); + signals[SIGHUP] = 0; + } + if (signals[SIGINFO]) { + char command[] = "status *"; + parseControl(command); + signals[SIGINFO] = 0; + } + struct pollfd fds[1 + 2 * services.len]; fds[0].fd = fifo; fds[0].events = POLLIN; @@ -393,31 +418,6 @@ int main(int argc, char *argv[]) { } setTitle(); } - - if (signals[SIGCHLD]) { - int status; - pid_t pid; - while (0 < (pid = waitpid(-1, &status, WNOHANG))) { - serviceReap(pid, status); - } - if (pid < 0 && errno != ECHILD) syslog(LOG_WARNING, "waitpid: %m"); - setTitle(); - signals[SIGCHLD] = 0; - } - - if (signals[SIGINT] || signals[SIGTERM]) { - break; - } - if (signals[SIGHUP]) { - parseConfig(configPath); - setTitle(); - signals[SIGHUP] = 0; - } - if (signals[SIGINFO]) { - char command[] = "status *"; - parseControl(command); - signals[SIGINFO] = 0; - } } close(fifo); -- cgit 1.4.1