]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
fix userns helper error handling
authorTycho Andersen <tycho@tycho.ws>
Fri, 9 Feb 2018 13:26:31 +0000 (13:26 +0000)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 12 Feb 2018 16:21:32 +0000 (17:21 +0100)
In both of these cases if there is actually an error, we won't close the
pipe and the api call will hang. Instead, let's be sure to close the pipe
before waiting, so that it doesn't hang.

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

index 640e37095b4e43a150a0d62a80984de6af29c72c..2e66b019a639286d5948d7f6a9617adcf93166ae 100644 (file)
@@ -3796,14 +3796,14 @@ int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data,
        }
 
 on_error:
-       /* Wait for child to finish. */
-       if (pid > 0)
-               status = wait_for_pid(pid);
-
        if (p[0] != -1)
                close(p[0]);
        close(p[1]);
 
+       /* Wait for child to finish. */
+       if (pid > 0)
+               status = wait_for_pid(pid);
+
        if (status < 0)
                ret = -1;
 
@@ -3971,6 +3971,10 @@ int userns_exec_full(struct lxc_conf *conf, int (*fn)(void *), void *data,
        }
 
 on_error:
+       if (p[0] != -1)
+               close(p[0]);
+       close(p[1]);
+
        /* Wait for child to finish. */
        if (pid > 0)
                ret = wait_for_pid(pid);
@@ -3982,10 +3986,6 @@ on_error:
        if (host_gid_map && (host_gid_map != container_root_gid))
                free(host_gid_map);
 
-       if (p[0] != -1)
-               close(p[0]);
-       close(p[1]);
-
        return ret;
 }