diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/librc/librc-depend.c | 3 | ||||
-rw-r--r-- | src/rc/rc-plugin.c | 17 | ||||
-rw-r--r-- | src/rc/rc.c | 18 | ||||
-rw-r--r-- | src/rc/runscript.c | 2 |
4 files changed, 18 insertions, 22 deletions
diff --git a/src/librc/librc-depend.c b/src/librc/librc-depend.c index ac8245fd..c28ccc77 100644 --- a/src/librc/librc-depend.c +++ b/src/librc/librc-depend.c @@ -566,6 +566,9 @@ RC_STRINGLIST *rc_deptree_order(const RC_DEPTREE *deptree, } } + if (!list) + return NULL; + /* Now we have our lists, we need to pull in any dependencies and order them */ types = rc_stringlist_new(); diff --git a/src/rc/rc-plugin.c b/src/rc/rc-plugin.c index 230a85a4..8599af6f 100644 --- a/src/rc/rc-plugin.c +++ b/src/rc/rc-plugin.c @@ -122,14 +122,15 @@ int rc_waitpid(pid_t pid) { int status = 0; pid_t savedpid = pid; - int retval = -1; - - errno = 0; - while ((pid = waitpid(savedpid, &status, 0)) > 0) { - if (pid == savedpid) - retval = WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE; - } - + int retval = EXIT_FAILURE; + + do { + pid = waitpid(savedpid, &status, 0); + if (pid == -1 && errno != EINTR) + return EXIT_FAILURE; + } while (!WIFEXITED(status) && !WIFSIGNALED(status)); + if (pid == savedpid) + retval = WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE; return retval; } diff --git a/src/rc/rc.c b/src/rc/rc.c index b8149239..91fe8393 100644 --- a/src/rc/rc.c +++ b/src/rc/rc.c @@ -279,7 +279,6 @@ static void mark_interactive(void) static void sulogin(bool cont) { - int status = 0; struct sigaction sa; sigset_t full; sigset_t old; @@ -346,7 +345,7 @@ static void sulogin(bool cont) /* Unmask signals and wait for child */ sigprocmask(SIG_SETMASK, &old, NULL); - waitpid(pid, &status, 0); + rc_waitpid(pid); } static void single_user(void) @@ -449,7 +448,7 @@ static void handle_signal(int sig) eerror("waitpid: %s", strerror(errno)); return; } - } while (! WIFEXITED(status) && ! WIFSIGNALED(status)); + } while (!WIFEXITED(status) && !WIFSIGNALED(status)); /* Remove that pid from our list */ if (pid > 0) @@ -513,9 +512,7 @@ static void handle_signal(int sig) static void run_script(const char *script) { - int status = 0; pid_t pid = vfork(); - pid_t wpid; if (pid < 0) eerrorx("%s: vfork: %s", applet, strerror(errno)); @@ -526,13 +523,7 @@ static void run_script(const char *script) _exit(EXIT_FAILURE); } - do { - wpid = waitpid(pid, &status, 0); - if (wpid < 1) - eerror("waitpid: %s", strerror(errno)); - } while (! WIFEXITED(status) && ! WIFSIGNALED(status)); - - if (! WIFEXITED(status) || ! WEXITSTATUS(status) == 0) + if (rc_waitpid(pid) != 0) eerrorx("%s: failed to exec `%s'", applet, script); } @@ -1059,7 +1050,8 @@ int main(int argc, char **argv) rc_logger_open(newlevel ? newlevel : runlevel); /* Setup a signal handler */ - signal_setup(SIGINT, handle_signal); + if (signal_setup(SIGINT, handle_signal) != 0) + eerror ("signal_setup: %s", strerror(errno)); signal_setup(SIGQUIT, handle_signal); signal_setup(SIGTERM, handle_signal); signal_setup(SIGUSR1, handle_signal); diff --git a/src/rc/runscript.c b/src/rc/runscript.c index 5977715a..d3cd7372 100644 --- a/src/rc/runscript.c +++ b/src/rc/runscript.c @@ -156,7 +156,7 @@ static void handle_signal(int sig) if (write(signal_pipe[1], &sig, sizeof(sig)) == -1) eerror("%s: send: %s", service, strerror(errno)); } else - rc_waitpid (-1); + rc_waitpid(-1); break; case SIGWINCH: |