conf: non-functional changes lxc_fill_autodev()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner 2017-05-08 19:38:59 +02:00
parent 218a8306c2
commit 0bbf8572ba
No known key found for this signature in database
GPG Key ID: 8EB056D53EECB12D

View File

@ -1172,25 +1172,24 @@ static const struct lxc_devs lxc_devs[] = {
{ "console", S_IFCHR | S_IRUSR | S_IWUSR, 5, 1 },
};
static int fill_autodev(const struct lxc_rootfs *rootfs, bool mount_console)
static int lxc_fill_autodev(const struct lxc_rootfs *rootfs, bool mount_console)
{
int ret;
char path[MAXPATHLEN];
int i;
mode_t cmask;
INFO("Creating initial consoles under container /dev");
ret = snprintf(path, MAXPATHLEN, "%s/dev", rootfs->path ? rootfs->mount : "");
if (ret < 0 || ret >= MAXPATHLEN) {
ERROR("Error calculating container /dev location");
return -1;
}
if (!dir_exists(path)) // ignore, just don't try to fill in
/* ignore, just don't try to fill in */
if (!dir_exists(path))
return 0;
INFO("Populating container /dev");
INFO("populating container /dev");
cmask = umask(S_IXUSR | S_IXGRP | S_IXOTH);
for (i = 0; i < sizeof(lxc_devs) / sizeof(lxc_devs[0]); i++) {
const struct lxc_devs *d = &lxc_devs[i];
@ -1201,13 +1200,20 @@ static int fill_autodev(const struct lxc_rootfs *rootfs, bool mount_console)
ret = snprintf(path, MAXPATHLEN, "%s/dev/%s", rootfs->path ? rootfs->mount : "", d->name);
if (ret < 0 || ret >= MAXPATHLEN)
return -1;
ret = mknod(path, d->mode, makedev(d->maj, d->min));
if (ret && errno != EEXIST) {
if (ret < 0) {
char hostpath[MAXPATHLEN];
FILE *pathfile;
// Unprivileged containers cannot create devices, so
// bind mount the device from the host
if (errno == EEXIST) {
DEBUG("\"%s\" device already existed", path);
continue;
}
/* Unprivileged containers cannot create devices, so
* bind mount the device from the host.
*/
ret = snprintf(hostpath, MAXPATHLEN, "/dev/%s", d->name);
if (ret < 0 || ret >= MAXPATHLEN)
return -1;
@ -1217,17 +1223,18 @@ static int fill_autodev(const struct lxc_rootfs *rootfs, bool mount_console)
return -1;
}
fclose(pathfile);
if (safe_mount(hostpath, path, 0, MS_BIND, NULL,
rootfs->path ? rootfs->mount : NULL) != 0) {
SYSERROR("Failed bind mounting device %s from host into container",
d->name);
if (safe_mount(hostpath, path, 0, MS_BIND, NULL, rootfs->path ? rootfs->mount : NULL) != 0) {
SYSERROR("Failed bind mounting device %s from host into container", d->name);
return -1;
}
DEBUG("bind mounted \"%s\" onto \"%s\"", hostpath, path);
} else {
DEBUG("created device node \"%s\"", path);
}
}
umask(cmask);
INFO("Populated container /dev");
INFO("populated container /dev");
return 0;
}
@ -4047,7 +4054,7 @@ int lxc_setup(struct lxc_handler *handler)
ERROR("failed to run autodev hooks for container '%s'.", name);
return -1;
}
if (fill_autodev(&lxc_conf->rootfs, mount_console)) {
if (lxc_fill_autodev(&lxc_conf->rootfs, mount_console)) {
ERROR("failed to populate /dev in the container");
return -1;
}