]> git.proxmox.com Git - mirror_lxc.git/commitdiff
lxccontainer: fix temporary path removal
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 30 Oct 2018 22:48:14 +0000 (23:48 +0100)
committerStéphane Graber <stgraber@ubuntu.com>
Thu, 1 Nov 2018 15:07:15 +0000 (11:07 -0400)
Needed-by: https://github.com/lxc/lxd/issues/5227
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/lxccontainer.c

index 6c35ab6532c207fa171805145123c9a9f14c468d..83ff24253b2704a60d1c5973b104ceaad11524e7 100644 (file)
@@ -4976,6 +4976,7 @@ static int do_lxcapi_mount(struct lxc_container *c, const char *source,
        char template[PATH_MAX], path[PATH_MAX];
        pid_t pid, init_pid;
        struct stat sb;
+       bool is_dir;
        int ret = -1, fd = -EBADF;
 
        if (!c || !c->lxc_conf) {
@@ -5006,7 +5007,8 @@ static int do_lxcapi_mount(struct lxc_container *c, const char *source,
                }
        }
 
-       if (S_ISDIR(sb.st_mode)) {
+       is_dir = (S_ISDIR(sb.st_mode) != 0);
+       if (is_dir) {
                sret = mkdtemp(template);
                if (!sret) {
                        SYSERROR("Could not create shmounts temporary dir");
@@ -5089,7 +5091,10 @@ static int do_lxcapi_mount(struct lxc_container *c, const char *source,
        ret = 0;
 
        (void)umount2(template, MNT_DETACH);
-       (void)unlink(template);
+       if (is_dir)
+               (void)rmdir(template);
+       else
+               (void)unlink(template);
 
 out:
        if (fd >= 0)