Fix WIFEXITED() logic when collecting reaped processes

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2023-03-21 11:24:17 +01:00
1 parent 3ce5a2a965
commit be9d54561d
2 files changed
+7 -9

No files matched your search

+3 -5
View File
@@ -484,7 +484,6 @@ int run_parts(char *dir, char *cmd, const char *env[], int progress)
}; };
pid_t pid = 0; pid_t pid = 0;
int status; int status;
int exit_status;
paste(path, sizeof(path), dir, name); paste(path, sizeof(path), dir, name);
if (stat(path, &st)) { if (stat(path, &st)) {
@@ -521,13 +520,12 @@ int run_parts(char *dir, char *cmd, const char *env[], int progress)
} }
status = complete(path, pid); status = complete(path, pid);
exit_status = WEXITSTATUS(status); if (WIFEXITED(status))
if (WIFEXITED(status) && exit_status) warnx("%s exited with status %d", path, WEXITSTATUS(status));
warnx("%s exited with status %d", path, exit_status);
else if (WIFSIGNALED(status)) else if (WIFSIGNALED(status))
warnx("%s terminated by signad %d", path, WTERMSIG(status)); warnx("%s terminated by signad %d", path, WTERMSIG(status));
if (progress) if (progress)
print_result(status); print_result(WEXITSTATUS(status));
} }
while (num--) while (num--)
+4 -4
View File
@@ -820,9 +820,9 @@ static int service_start(svc_t *svc)
dbg("collected %s(%d), normal exit: %d, signaled: %d, exit code: %d", 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)); WIFSIGNALED(svc->status), WEXITSTATUS(svc->status));
if (WIFEXITED(svc->status) && !WEXITSTATUS(svc->status)) { if (WIFEXITED(svc->status)) {
svc->started = 1; svc->started = 1;
result = 0; result = WEXITSTATUS(svc->status);
} else { } else {
svc->started = 0; svc->started = 0;
result = 1; result = 1;
@@ -1858,7 +1858,7 @@ void service_monitor(pid_t lost, int status)
service_cleanup(svc); service_cleanup(svc);
} else if (svc_is_runtask(svc)) { } else if (svc_is_runtask(svc)) {
/* run/task should run at least once per runlevel */ /* run/task should run at least once per runlevel */
if (WIFEXITED(status) && !WEXITSTATUS(status)) if (WIFEXITED(status))
svc->started = 1; svc->started = 1;
else else
svc->started = 0; 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. */ /* create success/failure condition when entering SVC_DONE_STATE. */
if (*state == SVC_DONE_STATE) { if (*state == SVC_DONE_STATE) {
if (svc->started) if (svc->started && !WEXITSTATUS(svc->status))
cond_set_oneshot(success); cond_set_oneshot(success);
else else
cond_set_oneshot(failure); cond_set_oneshot(failure);