]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: non-functional changes to setup_pts()
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 21 Apr 2017 20:37:27 +0000 (22:37 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 21 Apr 2017 21:40:38 +0000 (23:40 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c

index 9c6019a46169c83266901318ec05142b6f176b38..50e2b88596b89ba531375b3c67c732c5ffe3b78e 100644 (file)
@@ -1453,50 +1453,67 @@ static int setup_pivot_root(const struct lxc_rootfs *rootfs)
        return 0;
 }
 
-static int setup_pts(int pts)
+static int lxc_setup_devpts(int num_pts)
 {
+       int ret;
        char target[PATH_MAX];
+       char *devpts_mntopts = "newinstance,ptmxmode=0666,mode=0620,gid=5";
 
-       if (!pts)
+       if (!num_pts) {
+               DEBUG("no new devpts instance will be mounted since no pts "
+                     "devices are requested");
                return 0;
-
-       if (!access("/dev/pts/ptmx", F_OK) && umount("/dev/pts")) {
-               SYSERROR("failed to umount 'dev/pts'");
-               return -1;
        }
 
-       if (mkdir("/dev/pts", 0755)) {
-               if ( errno != EEXIST ) {
-                   SYSERROR("failed to create '/dev/pts'");
-                   return -1;
+       ret = access("/dev/pts/ptmx", F_OK);
+       if (!ret) {
+               /* Unmount old devpts instance. */
+               ret = umount("/dev/pts");
+               if (ret < 0) {
+                       SYSERROR("failed to unmount old devpts instance");
+                       return -1;
                }
+               DEBUG("unmounted old /dev/pts instance");
        }
 
-       if (mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL,
-                 "newinstance,ptmxmode=0666,mode=0620,gid=5")) {
-               SYSERROR("failed to mount a new instance of '/dev/pts'");
+       /* Create mountpoint for devpts instance. */
+       ret = mkdir("/dev/pts", 0755);
+       if (ret < 0 && errno != EEXIST) {
+               SYSERROR("failed to create the \"/dev/pts\" directory");
                return -1;
        }
 
-       if (access("/dev/ptmx", F_OK)) {
-               if (!symlink("/dev/pts/ptmx", "/dev/ptmx"))
-                       goto out;
-               SYSERROR("failed to symlink '/dev/pts/ptmx'->'/dev/ptmx'");
+       /* Mount new devpts instance. */
+       ret = mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, devpts_mntopts);
+       if (ret < 0) {
+               SYSERROR("failed to mount new devpts instance");
+               return -1;
+       }
+
+       ret = access("/dev/ptmx", F_OK);
+       if (ret < 0) {
+               ret = symlink("/dev/pts/ptmx", "/dev/ptmx");
+               if (!ret) {
+                       DEBUG("created symlink \"/dev/ptmx\" -> \"/dev/pts/ptmx\"");
+                       goto success;
+               }
+               SYSERROR("failed to create symlink \"/dev/ptmx\" -> \"/dev/pts/ptmx\"");
                return -1;
        }
 
+       /* Check if any existing symlink is valid. */
        if (realpath("/dev/ptmx", target) && !strcmp(target, "/dev/pts/ptmx"))
-               goto out;
+               goto success;
 
-       /* fallback here, /dev/pts/ptmx exists just mount bind */
-       if (mount("/dev/pts/ptmx", "/dev/ptmx", "none", MS_BIND, 0)) {
-               SYSERROR("mount failed '/dev/pts/ptmx'->'/dev/ptmx'");
+       /* Fallback here, /dev/pts/ptmx exists so just bind mount it. */
+       ret = mount("/dev/pts/ptmx", "/dev/ptmx", "none", MS_BIND, 0);
+       if (ret < 0) {
+               SYSERROR("failed to bind mount \"/dev/pts/ptmx\" to \"/dev/ptmx\"");
                return -1;
        }
 
-       INFO("created new pts instance");
-
-out:
+success:
+       INFO("created new devpts instance");
        return 0;
 }
 
@@ -4114,7 +4131,7 @@ int lxc_setup(struct lxc_handler *handler)
                return -1;
        }
 
-       if (setup_pts(lxc_conf->pts)) {
+       if (lxc_setup_devpts(lxc_conf->pts)) {
                ERROR("failed to setup the new pts instance");
                return -1;
        }