From: Christian Brauner Date: Mon, 9 Jul 2018 12:25:48 +0000 (+0200) Subject: conf: create /dev directory X-Git-Tag: lxc-3.1.0~214^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87e0e27360fafef4137096837d7ea298b57a0b1f;p=thirdparty%2Flxc.git conf: create /dev directory If users specified lxc.autodev = 1 it does not make sense to skip setting up autodev if /dev does not exist. We rather should create it. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index c8b75f8b9..d8c6eda1a 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -1191,6 +1191,7 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs, int ret; size_t clen; char *path; + mode_t cur_mask; INFO("Preparing \"/dev\""); @@ -1202,37 +1203,45 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs, if (ret < 0 || (size_t)ret >= clen) return -1; - if (!dir_exists(path)) { - WARN("\"/dev\" directory does not exist. Proceeding without " - "autodev being set up"); - return 0; + cur_mask = umask(S_IXUSR | S_IXGRP | S_IXOTH); + ret = mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + if (ret < 0 && errno != EEXIST) { + SYSERROR("Failed to create \"/dev\" directory"); + ret = -errno; + goto reset_umask; } ret = safe_mount("none", path, "tmpfs", 0, "size=500000,mode=755", rootfs->path ? rootfs->mount : NULL); if (ret < 0) { SYSERROR("Failed to mount tmpfs on \"%s\"", path); - return -1; + goto reset_umask; } - INFO("Mounted tmpfs on \"%s\"", path); + TRACE("Mounted tmpfs on \"%s\"", path); ret = snprintf(path, clen, "%s/dev/pts", rootfs->path ? rootfs->mount : ""); - if (ret < 0 || (size_t)ret >= clen) - return -1; + if (ret < 0 || (size_t)ret >= clen) { + ret = -1; + goto reset_umask; + } /* If we are running on a devtmpfs mapping, dev/pts may already exist. * If not, then create it and exit if that fails... */ - if (!dir_exists(path)) { - ret = mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); - if (ret < 0) { - SYSERROR("Failed to create directory \"%s\"", path); - return -1; - } + ret = mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + if (ret < 0 && errno != EEXIST) { + SYSERROR("Failed to create directory \"%s\"", path); + ret = -errno; + goto reset_umask; } + ret = 0; + +reset_umask: + (void)umask(cur_mask); + INFO("Prepared \"/dev\""); - return 0; + return ret; } struct lxc_device_node {