mirror of
https://github.com/systemd/systemd.git
synced 2024-12-26 03:22:00 +03:00
namespace: extract clone_device_node function from mount_private_dev
This commit is contained in:
parent
aad67b80c5
commit
b5e99f23ed
@ -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,42 +591,9 @@ 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);
|
||||
|
Loading…
Reference in New Issue
Block a user