From 39d60cdfef5d4ee49328f8642750385e99e08049 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Thu, 6 Dec 2012 13:08:56 +0300 Subject: [PATCH] rst: Sanitize sigchld handler The error handling was not obvious. Clean it up. Signed-off-by: Pavel Emelyanov --- cr-restore.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/cr-restore.c b/cr-restore.c index af9b2d9cb..c2a69239d 100644 --- a/cr-restore.c +++ b/cr-restore.c @@ -878,7 +878,6 @@ static void sigchld_handler(int signal, siginfo_t *siginfo, void *data) if (!current || status) goto err; - /* Skip a helper if it was completed successfully */ while (pid) { pid = waitpid(-1, &status, WNOHANG); if (pid <= 0) @@ -889,15 +888,14 @@ static void sigchld_handler(int signal, siginfo_t *siginfo, void *data) if (status) break; - list_for_each_entry(pi, ¤t->children, sibling) { - if (pi->state != TASK_HELPER) - continue; + /* Exited (with zero code) helpers are OK */ + list_for_each_entry(pi, ¤t->children, sibling) if (pi->pid.virt == siginfo->si_pid) break; - } - if (&pi->sibling == ¤t->children) - break; /* The process is not a helper */ + BUG_ON(&pi->sibling == ¤t->children); + if (pi->state != TASK_HELPER) + break; } err: