diff options
author | June McEnroe <june@causal.agency> | 2021-02-01 11:36:31 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2021-02-01 11:36:31 -0500 |
commit | da4ccb18f4c6900c6e5ad39e226cab9699837412 (patch) | |
tree | abb08465d5b6c1e811e6a99c7de0e5d29d14cd99 | |
parent | Log a message when stopping a service waiting to restart (diff) | |
download | catsit-da4ccb18f4c6900c6e5ad39e226cab9699837412.tar.gz catsit-da4ccb18f4c6900c6e5ad39e226cab9699837412.zip |
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.
Diffstat (limited to '')
-rw-r--r-- | daemon.c | 50 |
1 files 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); |