]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc-execute: actually exit with the status of the spawned task
authorTycho Andersen <tycho@tycho.ws>
Fri, 19 Jan 2018 03:31:33 +0000 (03:31 +0000)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 19 Jan 2018 14:20:06 +0000 (15:20 +0100)
Now that we have things propagated through init and liblxc correctly, at
least in non-daemon mode, we can exit with the actual exit status of the
task, instead of always succeeding, which is not so helpful.

Signed-off-by: Tycho Andersen <tycho@tycho.ws>
src/lxc/tools/lxc_execute.c

index 73b12662fc28a3631a56997a12bbf017c7e837ce..ce49b5da693716d4a5deb96d01b8ed7cfefe9563 100644 (file)
@@ -168,14 +168,20 @@ int main(int argc, char *argv[])
 
        c->daemonize = false;
        bret = c->start(c, 1, my_args.argv);
-       if (c->daemonize)
-               ret = EXIT_SUCCESS;
-       else
-               ret = c->error_num;
        lxc_container_put(c);
        if (!bret) {
                fprintf(stderr, "Failed run an application inside container\n");
                exit(EXIT_FAILURE);
        }
-       exit(ret);
+       if (c->daemonize)
+               exit(EXIT_SUCCESS);
+       else {
+               if (WIFEXITED(c->error_num)) {
+                       exit(WEXITSTATUS(c->error_num));
+               } else {
+                       /* Try to die with the same signal the task did. */
+                       kill(0, WTERMSIG(c->error_num));
+                       exit(EXIT_FAILURE);
+               }
+       }
 }