← Commit list

f9274e8d6

Sébastien Parisot
Sébastien Parisot
2025-04-06
SUCCESS Duration: 159s

Subject

init: improve log message when a process exits: show exit code

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

init/init.c+15 -3
@@ -1198,17 +1198,29 @@ int init_main(int argc UNUSED_PARAM, char **argv)
/* Wait for any child process(es) to exit */
while (1) {
pid_t wpid;
+ int status;
struct init_action *a;
- wpid = waitpid(-1, NULL, WNOHANG);
+ wpid = waitpid(-1, &status, WNOHANG);
if (wpid <= 0)
break;
a = mark_terminated(wpid);
if (a) {
- message(L_LOG, "process '%s' (pid %u) exited. "
+ const char *s = "killed, signal";
+ int ex = WTERMSIG(status);
+ /* "if (!WIFSIGNALED(status))" generates more code:
+ * on linux, WIFEXITED(status) is "WTERMSIG(status) == 0"
+ * and WTERMSIG(status) is known, so compiler optimizes.
+ */
+ if (WIFEXITED(status)) {
+ s = "exited, exitcode";
+ ex = WEXITSTATUS(status);
+ }
+ message(L_LOG, "process '%s' (pid %u) %s:%d. "
"Scheduling for restart.",
- a->command, (unsigned)wpid);
+ a->command, (unsigned)wpid,
+ s, ex);
}
}