The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/849

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Previously, we called lxc_container_put() before waitpid(). Let's do it the
other way around.

Signed-off-by: Christian Brauner <christian.brau...@mailbox.org>
From 653ed513eb25c84ec3db4e528dc3cdb1a13b3a1f Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@mailbox.org>
Date: Thu, 25 Feb 2016 15:22:53 +0100
Subject: [PATCH] lxc-attach: fix cleanup code

Previously, we called lxc_container_put() before waitpid(). Let's do it the
other way around.

Signed-off-by: Christian Brauner <christian.brau...@mailbox.org>
---
 src/lxc/lxc_attach.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/lxc/lxc_attach.c b/src/lxc/lxc_attach.c
index 3439b2f..6501140 100644
--- a/src/lxc/lxc_attach.c
+++ b/src/lxc/lxc_attach.c
@@ -475,6 +475,7 @@ static int pty_on_host(struct lxc_container *c, struct 
wrapargs *wrap, int *pid)
 int main(int argc, char *argv[])
 {
        int ret = -1;
+       int wexit = 0;
        pid_t pid;
        lxc_attach_options_t attach_options = LXC_ATTACH_OPTIONS_DEFAULT;
        lxc_attach_command_t command = (lxc_attach_command_t){.program = NULL};
@@ -554,17 +555,18 @@ int main(int argc, char *argv[])
                        ret = c->attach(c, lxc_attach_run_shell, NULL, 
&attach_options, &pid);
        }
 
-       lxc_container_put(c);
-
        if (ret < 0)
-               exit(EXIT_FAILURE);
+               goto out;
 
        ret = lxc_wait_for_pid_status(pid);
        if (ret < 0)
-               exit(EXIT_FAILURE);
+               goto out;
 
        if (WIFEXITED(ret))
-               return WEXITSTATUS(ret);
-
+               wexit = WEXITSTATUS(ret);
+out:
+       lxc_container_put(c);
+       if (ret >= 0)
+               exit(wexit);
        exit(EXIT_FAILURE);
 }
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to