From be9d54561d2ae1629faff59d8cf2399780b76f17 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 19 Mar 2023 09:27:47 +0100 Subject: [PATCH] Fix WIFEXITED() logic when collecting reaped processes Signed-off-by: Joachim Wiberg --- src/exec.c | 8 +++----- src/service.c | 10 +++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/exec.c b/src/exec.c index 627885b7..5d967c37 100644 --- a/src/exec.c +++ b/src/exec.c @@ -484,7 +484,6 @@ int run_parts(char *dir, char *cmd, const char *env[], int progress) }; pid_t pid = 0; int status; - int exit_status; paste(path, sizeof(path), dir, name); if (stat(path, &st)) { @@ -521,13 +520,12 @@ int run_parts(char *dir, char *cmd, const char *env[], int progress) } status = complete(path, pid); - exit_status = WEXITSTATUS(status); - if (WIFEXITED(status) && exit_status) - warnx("%s exited with status %d", path, exit_status); + if (WIFEXITED(status)) + warnx("%s exited with status %d", path, WEXITSTATUS(status)); else if (WIFSIGNALED(status)) warnx("%s terminated by signad %d", path, WTERMSIG(status)); if (progress) - print_result(status); + print_result(WEXITSTATUS(status)); } while (num--) diff --git a/src/service.c b/src/service.c index dda6748c..c74df8a4 100644 --- a/src/service.c +++ b/src/service.c @@ -818,11 +818,11 @@ static int service_start(svc_t *svc) case SVC_TYPE_RUN: svc->status = complete(svc->cmd, pid); dbg("collected %s(%d), normal exit: %d, signaled: %d, exit code: %d", - svc_ident(svc, NULL, 0), pid, WIFEXITED(svc->status), + svc_ident(svc, NULL, 0), pid, WIFEXITED(svc->status), WIFSIGNALED(svc->status), WEXITSTATUS(svc->status)); - if (WIFEXITED(svc->status) && !WEXITSTATUS(svc->status)) { + if (WIFEXITED(svc->status)) { svc->started = 1; - result = 0; + result = WEXITSTATUS(svc->status); } else { svc->started = 0; result = 1; @@ -1858,7 +1858,7 @@ void service_monitor(pid_t lost, int status) service_cleanup(svc); } else if (svc_is_runtask(svc)) { /* run/task should run at least once per runlevel */ - if (WIFEXITED(status) && !WEXITSTATUS(status)) + if (WIFEXITED(status)) svc->started = 1; else svc->started = 0; @@ -2172,7 +2172,7 @@ static void svc_set_state(svc_t *svc, svc_state_t new_state) /* create success/failure condition when entering SVC_DONE_STATE. */ if (*state == SVC_DONE_STATE) { - if (svc->started) + if (svc->started && !WEXITSTATUS(svc->status)) cond_set_oneshot(success); else cond_set_oneshot(failure);