conf: improve lxc_setup_dev_console()

In case the user did request a console to be set up unmount any prior bind-mount for it. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 3d7d929a
...@@ -1490,10 +1490,38 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs, ...@@ -1490,10 +1490,38 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
char path[MAXPATHLEN]; char path[MAXPATHLEN];
int ret, fd; int ret, fd;
if (console->path && !strcmp(console->path, "none"))
return 0;
ret = snprintf(path, sizeof(path), "%s/dev/console", rootfs->mount); ret = snprintf(path, sizeof(path), "%s/dev/console", rootfs->mount);
if (ret < 0 || (size_t)ret >= sizeof(path)) if (ret < 0 || (size_t)ret >= sizeof(path))
return -1; return -1;
/* When we are asked to setup a console we remove any previous
* /dev/console bind-mounts.
*/
ret = umount(path);
if (ret < 0) {
if (errno != EINVAL && errno != ENOENT) {
/* EINVAL: path is not a mountpoint
* ENOENT: path does not exist
* anything else means something weird is happening.
*/
ERROR("failed to unmount \"%s\": %s", path, strerror(errno));
return -errno;
}
} else {
DEBUG("unmounted console \"%s\"", path);
}
ret = unlink(path);
if (ret && errno != ENOENT) {
SYSERROR("error unlinking %s", path);
return -errno;
}
/* For unprivileged containers autodev or automounts will already have
* taken care of creating /dev/console.
*/
fd = open(path, O_CREAT | O_EXCL, S_IXUSR | S_IXGRP | S_IXOTH); fd = open(path, O_CREAT | O_EXCL, S_IXUSR | S_IXGRP | S_IXOTH);
if (fd < 0) { if (fd < 0) {
if (errno != EEXIST) { if (errno != EEXIST) {
...@@ -1504,11 +1532,6 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs, ...@@ -1504,11 +1532,6 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
close(fd); close(fd);
} }
if (console->master < 0) {
INFO("no console");
return 0;
}
if (chmod(console->name, S_IXUSR | S_IXGRP | S_IXOTH)) { if (chmod(console->name, S_IXUSR | S_IXGRP | S_IXOTH)) {
SYSERROR("failed to set mode '0%o' to '%s'", S_IXUSR | S_IXGRP | S_IXOTH, console->name); SYSERROR("failed to set mode '0%o' to '%s'", S_IXUSR | S_IXGRP | S_IXOTH, console->name);
return -errno; return -errno;
......
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