Commit 3c26f34e by dlezcano

setup the new pts instance

From: Daniel Lezcano <dlezcano@fr.ibm.com> The pts new instance is setup conforming the documentation in the kernel sources, Documentation/filesystems/devpts.txt. Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 10db618d
...@@ -759,6 +759,43 @@ static int setup_rootfs(const char *name) ...@@ -759,6 +759,43 @@ static int setup_rootfs(const char *name)
return 0; return 0;
} }
static int setup_pts(const char *name)
{
char mountname[MAXPATHLEN];
if (!access("/dev/pts/ptmx", F_OK) && umount("/dev/pts")) {
lxc_log_syserror("failed to umount 'dev/pts'");
return -1;
}
snprintf(mountname, MAXPATHLEN, "%spts", name);
if (mount(mountname, "/dev/pts", "devpts", MS_MGC_VAL, "newinstance")) {
lxc_log_syserror("failed to mount a new instance of '/dev/pts'");
return -1;
}
if (chmod("/dev/pts/ptmx", 0666)) {
lxc_log_syserror("failed to set permission for '/dev/pts/ptmx'");
return -1;
}
if (access("/dev/ptmx", F_OK)) {
if (!symlink("/dev/pts/ptmx", "/dev/ptmx"))
goto out;
lxc_log_syserror("failed to symlink '/dev/pts/ptmx'->'/dev/ptmx'");
return -1;
}
/* fallback here, /dev/pts/ptmx exists just mount bind */
if (mount("/dev/pts/ptmx", "/dev/ptmx", "none", MS_BIND, 0)) {
lxc_log_syserror("mount failed '/dev/pts/ptmx'->'/dev/ptmx'");
return -1;
}
out:
return 0;
}
static int setup_console(const char *name, const char *tty) static int setup_console(const char *name, const char *tty)
{ {
char console[MAXPATHLEN]; char console[MAXPATHLEN];
...@@ -1572,7 +1609,7 @@ void lxc_delete_tty(struct lxc_tty_info *tty_info) ...@@ -1572,7 +1609,7 @@ void lxc_delete_tty(struct lxc_tty_info *tty_info)
tty_info->nbtty = 0; tty_info->nbtty = 0;
} }
enum { utsname, network, cgroup, fstab, console, tty, rootfs, }; enum { utsname, network, cgroup, fstab, console, tty, rootfs, pts };
static int conf_is_set(long flags, int subsystem) static int conf_is_set(long flags, int subsystem)
{ {
...@@ -1604,6 +1641,9 @@ static long make_conf_flagset(const char *name, const char *cons, ...@@ -1604,6 +1641,9 @@ static long make_conf_flagset(const char *name, const char *cons,
if (conf_has_rootfs(name)) if (conf_has_rootfs(name))
conf_set_flag(&flags, rootfs); conf_set_flag(&flags, rootfs);
if (conf_has_pts(name))
conf_set_flag(&flags, pts);
if (tty_info->nbtty) if (tty_info->nbtty)
conf_set_flag(&flags, tty); conf_set_flag(&flags, tty);
...@@ -1656,5 +1696,10 @@ int lxc_setup(const char *name, const char *cons, ...@@ -1656,5 +1696,10 @@ int lxc_setup(const char *name, const char *cons,
return -LXC_ERROR_SETUP_ROOTFS; return -LXC_ERROR_SETUP_ROOTFS;
} }
if (conf_is_set(flags, pts) && setup_pts(name)) {
lxc_log_error("failed to setup the new pts instance");
return -LXC_ERROR_SETUP_PTS;
}
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment