1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-07 09:56:51 +03:00

namespace: extract clone_device_node function from mount_private_dev

This commit is contained in:
Дамјан Георгиевски 2018-01-16 21:27:51 +01:00
parent aad67b80c5
commit b5e99f23ed

View File

@ -496,6 +496,40 @@ static void drop_outside_root(const char *root_directory, MountEntry *m, unsigne
*n = t - m;
}
static int clone_device_node(const char *d, const char *temporary_mount)
{
_cleanup_free_ char *dn = NULL;
struct stat st;
int r;
r = stat(d, &st);
if (r < 0) {
if (errno == ENOENT)
return 0;
return -errno;
}
if (!S_ISBLK(st.st_mode) &&
!S_ISCHR(st.st_mode))
return -EINVAL;
if (st.st_rdev == 0)
return 0;
dn = strappend(temporary_mount, d);
if (!dn)
return -ENOMEM;
mac_selinux_create_file_prepare(d, st.st_mode);
r = mknod(dn, st.st_mode, st.st_rdev);
mac_selinux_create_file_clear();
if (r < 0)
return -errno;
return 0;
}
static int mount_private_dev(MountEntry *m) {
static const char devnodes[] =
"/dev/null\0"
@ -557,44 +591,11 @@ static int mount_private_dev(MountEntry *m) {
(void) symlink("/run/systemd/journal/dev-log", devlog);
NULSTR_FOREACH(d, devnodes) {
_cleanup_free_ char *dn = NULL;
struct stat st;
r = stat(d, &st);
if (r < 0) {
if (errno == ENOENT)
continue;
r = -errno;
r = clone_device_node(d, temporary_mount);
if (r < 0)
goto fail;
}
if (!S_ISBLK(st.st_mode) &&
!S_ISCHR(st.st_mode)) {
r = -EINVAL;
goto fail;
}
if (st.st_rdev == 0)
continue;
dn = strappend(temporary_mount, d);
if (!dn) {
r = -ENOMEM;
goto fail;
}
mac_selinux_create_file_prepare(d, st.st_mode);
r = mknod(dn, st.st_mode, st.st_rdev);
mac_selinux_create_file_clear();
if (r < 0) {
r = -errno;
goto fail;
}
}
dev_setup(temporary_mount, UID_INVALID, GID_INVALID);
/* Create the /dev directory if missing. It is more likely to be