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: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 57d533fb
...@@ -1191,6 +1191,7 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs, ...@@ -1191,6 +1191,7 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs,
int ret; int ret;
size_t clen; size_t clen;
char *path; char *path;
mode_t cur_mask;
INFO("Preparing \"/dev\""); INFO("Preparing \"/dev\"");
...@@ -1202,37 +1203,45 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs, ...@@ -1202,37 +1203,45 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs,
if (ret < 0 || (size_t)ret >= clen) if (ret < 0 || (size_t)ret >= clen)
return -1; return -1;
if (!dir_exists(path)) { cur_mask = umask(S_IXUSR | S_IXGRP | S_IXOTH);
WARN("\"/dev\" directory does not exist. Proceeding without " ret = mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
"autodev being set up"); if (ret < 0 && errno != EEXIST) {
return 0; SYSERROR("Failed to create \"/dev\" directory");
ret = -errno;
goto reset_umask;
} }
ret = safe_mount("none", path, "tmpfs", 0, "size=500000,mode=755", ret = safe_mount("none", path, "tmpfs", 0, "size=500000,mode=755",
rootfs->path ? rootfs->mount : NULL); rootfs->path ? rootfs->mount : NULL);
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to mount tmpfs on \"%s\"", path); 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 : ""); ret = snprintf(path, clen, "%s/dev/pts", rootfs->path ? rootfs->mount : "");
if (ret < 0 || (size_t)ret >= clen) if (ret < 0 || (size_t)ret >= clen) {
return -1; ret = -1;
goto reset_umask;
}
/* If we are running on a devtmpfs mapping, dev/pts may already exist. /* If we are running on a devtmpfs mapping, dev/pts may already exist.
* If not, then create it and exit if that fails... * 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); ret = mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
if (ret < 0) { if (ret < 0 && errno != EEXIST) {
SYSERROR("Failed to create directory \"%s\"", path); SYSERROR("Failed to create directory \"%s\"", path);
return -1; ret = -errno;
} goto reset_umask;
} }
ret = 0;
reset_umask:
(void)umask(cur_mask);
INFO("Prepared \"/dev\""); INFO("Prepared \"/dev\"");
return 0; return ret;
} }
struct lxc_device_node { struct lxc_device_node {
......
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