From: Christian Brauner Date: Mon, 8 May 2017 19:11:58 +0000 (+0200) Subject: conf: improve lxc_setup_dev_console() X-Git-Tag: lxc-2.1.0~139^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b1b121003f63266ff5437eb3925b2a3ef428cdb;p=thirdparty%2Flxc.git 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: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index e338a55b4..0ba854b47 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -1490,10 +1490,38 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs, char path[MAXPATHLEN]; int ret, fd; + if (console->path && !strcmp(console->path, "none")) + return 0; + ret = snprintf(path, sizeof(path), "%s/dev/console", rootfs->mount); if (ret < 0 || (size_t)ret >= sizeof(path)) 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); if (fd < 0) { if (errno != EEXIST) { @@ -1504,11 +1532,6 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs, close(fd); } - if (console->master < 0) { - INFO("no console"); - return 0; - } - 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); return -errno;