core/namespace: create /dev/log only if journal socket is present

This commit is contained in:
Mike Yuan
2024-04-26 04:47:40 +08:00
parent 368a3071e9
commit 119820f8ab

View File

@@ -1084,7 +1084,7 @@ static int create_temporary_mount_point(RuntimeScope scope, char **ret) {
return 0;
}
static int mount_private_dev(MountEntry *m, RuntimeScope scope) {
static int mount_private_dev(const MountEntry *m, const NamespaceParameters *p) {
static const char devnodes[] =
"/dev/null\0"
"/dev/zero\0"
@@ -1099,8 +1099,9 @@ static int mount_private_dev(MountEntry *m, RuntimeScope scope) {
int r;
assert(m);
assert(p);
r = create_temporary_mount_point(scope, &temporary_mount);
r = create_temporary_mount_point(p->runtime_scope, &temporary_mount);
if (r < 0)
return r;
@@ -1145,9 +1146,13 @@ static int mount_private_dev(MountEntry *m, RuntimeScope scope) {
FOREACH_STRING(d, "/dev/mqueue", "/dev/hugepages")
(void) bind_mount_device_dir(temporary_mount, d);
const char *devlog = strjoina(temporary_mount, "/dev/log");
if (symlink("/run/systemd/journal/dev-log", devlog) < 0)
log_debug_errno(errno, "Failed to create symlink '%s' to /run/systemd/journal/dev-log, ignoring: %m", devlog);
if ((!p->root_image && !p->root_directory) || p->bind_journal_sockets) {
const char *devlog = strjoina(temporary_mount, "/dev/log");
if (symlink("/run/systemd/journal/dev-log", devlog) < 0)
log_debug_errno(errno,
"Failed to create symlink '%s' to /run/systemd/journal/dev-log, ignoring: %m",
devlog);
}
NULSTR_FOREACH(d, devnodes) {
r = clone_device_node(d, temporary_mount, &can_mknod);
@@ -1726,7 +1731,7 @@ static int apply_one_mount(
break;
case MOUNT_PRIVATE_DEV:
return mount_private_dev(m, p->runtime_scope);
return mount_private_dev(m, p);
case MOUNT_BIND_DEV:
return mount_bind_dev(m);