]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
utils: tweak lxc_mount_proc_if_needed() 1529/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 28 Apr 2017 22:03:06 +0000 (00:03 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 28 Apr 2017 22:05:42 +0000 (00:05 +0200)
Create /proc directory if it doesn't exist.

Closes #1475.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/utils.c

index 03386dd737273660042680eeafa3c672bbac8c4e..6458bbdce40bcea8ba21b946723f07e682ccd0dc 100644 (file)
@@ -1766,37 +1766,48 @@ int lxc_mount_proc_if_needed(const char *rootfs)
                SYSERROR("proc path name too long");
                return -1;
        }
+
        memset(link, 0, 20);
        linklen = readlink(path, link, 20);
        mypid = (int)getpid();
-       INFO("I am %d, /proc/self points to '%s'", mypid, link);
+       INFO("I am %d, /proc/self points to \"%s\"", mypid, link);
+
        ret = snprintf(path, MAXPATHLEN, "%s/proc", rootfs);
        if (ret < 0 || ret >= MAXPATHLEN) {
                SYSERROR("proc path name too long");
                return -1;
        }
-       if (linklen < 0) /* /proc not mounted */
+
+       /* /proc not mounted */
+       if (linklen < 0) {
+               if (mkdir(path, 0755) && errno != EEXIST)
+                       return -1;
                goto domount;
+       }
+
        if (lxc_safe_int(link, &link_to_pid) < 0)
                return -1;
+
+       /* wrong /procs mounted */
        if (link_to_pid != mypid) {
-               /* wrong /procs mounted */
-               umount2(path, MNT_DETACH); /* ignore failure */
+               /* ignore failure */
+               umount2(path, MNT_DETACH);
                goto domount;
        }
+
        /* the right proc is already mounted */
        return 0;
 
 domount:
-       if (!strcmp(rootfs,"")) /* rootfs is NULL */
+       /* rootfs is NULL */
+       if (!strcmp(rootfs,""))
                ret = mount("proc", path, "proc", 0, NULL);
        else
                ret = safe_mount("proc", path, "proc", 0, NULL, rootfs);
-
        if (ret < 0)
                return -1;
 
-       INFO("Mounted /proc in container for security transition");
+       INFO("mounted /proc in container for security transition");
        return 1;
 }