diff options
-rw-r--r-- | initd/runsvc.c | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/initd/runsvc.c b/initd/runsvc.c index 430f2e7..8aaa502 100644 --- a/initd/runsvc.c +++ b/initd/runsvc.c @@ -134,6 +134,12 @@ static __attribute__((noreturn)) void argv_exec(exec_t *e) static pid_t current_child; +static void runsvc_sighandler(int signo) +{ + if (current_child != -1) + kill(current_child, signo); +} + static int run_sequentially(exec_t *list, bool direct_exec_last) { pid_t ret, pid; @@ -158,7 +164,7 @@ static int run_sequentially(exec_t *list, bool direct_exec_last) current_child = pid; do { - ret = waitpid(pid, &status, 0); + ret = wait(&status); } while (ret != pid); current_child = -1; @@ -170,31 +176,19 @@ static int run_sequentially(exec_t *list, bool direct_exec_last) return WEXITSTATUS(status); } - return EXIT_SUCCESS; -} - -static void runsvc_sighandler(int signo) -{ - pid_t pid; + do { + ret = wait(&status); + } while (ret != -1 || errno != ECHILD); - switch (signo) { - case SIGCHLD: - while ((pid = waitpid(-1, NULL, WNOHANG)) > 0) - ; - break; - default: - if (current_child != -1) - kill(current_child, signo); - break; - } + return ret; } pid_t runsvc(service_t *svc) { struct sigaction act; sigset_t mask; - int i, ret; pid_t pid; + int ret; pid = fork(); @@ -205,11 +199,15 @@ pid_t runsvc(service_t *svc) sigfillset(&mask); sigprocmask(SIG_SETMASK, &mask, NULL); - for (i = 1; i < 32; ++i) { - memset(&act, 0, sizeof(act)); - act.sa_handler = runsvc_sighandler; - sigaction(i, &act, NULL); - } + memset(&act, 0, sizeof(act)); + act.sa_handler = runsvc_sighandler; + sigaction(SIGTERM, &act, NULL); + sigaction(SIGINT, &act, NULL); + sigaction(SIGHUP, &act, NULL); + + act.sa_handler = SIG_DFL; + sigaction(SIGCHLD, &act, NULL); + sigaction(SIGUSR1, &act, NULL); if (setup_env()) exit(EXIT_FAILURE); |