]> git.ipfire.org Git - pakfire.git/commitdiff
jail: Pass the program exit code as return code of the loop
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 22 Mar 2025 14:20:23 +0000 (14:20 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 22 Mar 2025 14:20:23 +0000 (14:20 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/jail.c

index b9da3124b93e716cf3ea05d3c1af4877d19e0bc5..da23a1cc1f448aa5b630e371b7a727cd99d79637 100644 (file)
@@ -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) {