From 3db3b82a3081f6db3cbee8926db19c1c072cc7d5 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 13 May 2020 17:13:32 +0200 Subject: 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 --- initd/main.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'initd/main.c') 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; -- cgit v1.2.3