From 2155d9085294a5e7eb17105e1111b8a0e1a9704e Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 22 Mar 2025 14:20:23 +0000 Subject: [PATCH] jail: Pass the program exit code as return code of the loop Signed-off-by: Michael Tremer --- src/pakfire/jail.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/pakfire/jail.c b/src/pakfire/jail.c index b9da3124..da23a1cc 100644 --- a/src/pakfire/jail.c +++ b/src/pakfire/jail.c @@ -120,9 +120,6 @@ struct pakfire_jail_exec { sd_event* loop; int flags; - // Exit Code - int exit; - // PID (of the child) pid_t pid; int pidfd; @@ -957,20 +954,21 @@ static int pakfire_jail_timer(sd_event_source* s, uint64_t usec, void* data) { static int pakfire_jail_exited(sd_event_source* source, const siginfo_t* si, void* data) { struct pakfire_jail_exec* ctx = data; struct pakfire_jail* jail = ctx->jail; + int r = 0; switch (si->si_code) { case CLD_EXITED: DEBUG(jail->ctx, "Process has exited with status code %d\n", si->si_status); // Store the exit code - ctx->exit = si->si_status; + r = si->si_status; break; case CLD_KILLED: ERROR(jail->ctx, "Process has been killed by signal %d\n", si->si_signo); // Store the exit code - ctx->exit = 139; + r = 139; break; case CLD_DUMPED: @@ -978,12 +976,12 @@ static int pakfire_jail_exited(sd_event_source* source, const siginfo_t* si, voi si->si_status); // Store the exit code - ctx->exit = 128 + si->si_status; + r = 128 + si->si_status; break; } // Terminate the event loop - return sd_event_exit(ctx->loop, 0); + return sd_event_exit(ctx->loop, r); } struct pakfire_jail_command { @@ -1359,9 +1357,6 @@ static int __pakfire_jail_exec(struct pakfire_jail* jail, // Callback & Data .callback = callback, .data = data, - - // Exit Code - .exit = -1, }; DEBUG(jail->ctx, "Executing jail...\n"); @@ -1546,9 +1541,6 @@ static int __pakfire_jail_exec(struct pakfire_jail* jail, goto ERROR; } - // Return the exit code - r = ctx.exit; - ERROR: // Destroy the temporary cgroup (if any) if (ctx.cgroup) { -- 2.39.5