Fix WIFEXITED() logic when collecting reaped processes

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-03-21 11:24:17 +01:00
parent 3ce5a2a965
commit be9d54561d
2 changed files with 8 additions and 10 deletions
+3 -5
View File
@@ -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--)
+5 -5
View File
@@ -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);