summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-04-26 14:57:39 +0000
committerRoy Marples <roy@marples.name>2008-04-26 14:57:39 +0000
commitb5d829789f6f4fabb02b7e995267f6e906b002ef (patch)
tree23c0e4bda08a2b06719ca2ececdb84de89ff3a8e
parent1e3442f95d2acd290e417f9b26e908c98c4a2c36 (diff)
downloadopenrc-b5d829789f6f4fabb02b7e995267f6e906b002ef.tar.gz
openrc-b5d829789f6f4fabb02b7e995267f6e906b002ef.tar.bz2
openrc-b5d829789f6f4fabb02b7e995267f6e906b002ef.tar.xz
Check we have a list before running depends.
-rw-r--r--src/librc/librc-depend.c3
-rw-r--r--src/rc/rc-plugin.c17
-rw-r--r--src/rc/rc.c18
-rw-r--r--src/rc/runscript.c2
4 files changed, 18 insertions, 22 deletions
diff --git a/src/librc/librc-depend.c b/src/librc/librc-depend.c
index ac8245f..c28ccc7 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 230a85a..8599af6 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 b814923..91fe839 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 5977715..d3cd737 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: