diff options
author | David Oberhollenzer <goliath@infraroot.at> | 2020-05-13 17:13:32 +0200 |
---|---|---|
committer | David Oberhollenzer <goliath@infraroot.at> | 2020-05-13 17:14:45 +0200 |
commit | 3db3b82a3081f6db3cbee8926db19c1c072cc7d5 (patch) | |
tree | 725c14982b8d0ef2451c249c0ee8b55da27fba2e /initd/main.c | |
parent | 9084f3862973aa5eccfafe51c6682a6aef123d4d (diff) |
Cleanup: Remove SIGCHLD handler from initd
Instead use wait() in the main loop. This way, the supervisor
functions (except set target) are no longer called from signal
context and can be simplified a little.
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
Diffstat (limited to 'initd/main.c')
-rw-r--r-- | initd/main.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/initd/main.c b/initd/main.c index 5ad265d..2d721a4 100644 --- a/initd/main.c +++ b/initd/main.c @@ -3,18 +3,7 @@ static void handle_signal(int signo) { - int status; - pid_t pid; - switch (signo) { - case SIGCHLD: - while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { - status = WIFEXITED(status) ? WEXITSTATUS(status) : - EXIT_FAILURE; - - supervisor_handle_exited(pid, status); - } - break; case SIGTERM: supervisor_set_target(TGT_SHUTDOWN); break; @@ -31,13 +20,14 @@ static void handle_signal(int signo) int main(void) { struct sigaction act; + int status; + pid_t pid; supervisor_init(); memset(&act, 0, sizeof(act)); act.sa_handler = handle_signal; - sigaction(SIGCHLD, &act, NULL); sigaction(SIGTERM, &act, NULL); sigaction(SIGINT, &act, NULL); sigaction(SIGHUP, &act, NULL); @@ -50,7 +40,14 @@ int main(void) while (supervisor_process_queues()) ; - pause(); + pid = wait(&status); + + if (pid != -1) { + status = WIFEXITED(status) ? + WEXITSTATUS(status) : EXIT_FAILURE; + + supervisor_handle_exited(pid, status); + } } return EXIT_SUCCESS; |