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.
This commit is contained in:
C. McEnroe 2021-02-01 11:36:31 -05:00
parent 7769a4f6e9
commit da4ccb18f4

View File

@ -321,6 +321,31 @@ int main(int argc, char *argv[]) {
sigset_t mask; sigset_t mask;
sigemptyset(&mask); sigemptyset(&mask);
for (;;) { 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]; struct pollfd fds[1 + 2 * services.len];
fds[0].fd = fifo; fds[0].fd = fifo;
fds[0].events = POLLIN; fds[0].events = POLLIN;
@ -393,31 +418,6 @@ int main(int argc, char *argv[]) {
} }
setTitle(); 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); close(fifo);