From dfb4b39d4d764a6242554d7b4d7f54f0197eca76 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 4 Nov 2025 11:04:50 +0100 Subject: [PATCH] core/socket: fix alignment, extract common conditions --- src/core/socket.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/core/socket.c b/src/core/socket.c index cc339d631d4..c53f84906fe 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1580,31 +1580,27 @@ static int socket_address_listen_in_cgroup( if (r < 0) return log_unit_error_errno(UNIT(s), r, "Failed to acquire runtime: %m"); - if (s->exec_context.user_namespace_path && - s->exec_runtime && - s->exec_runtime->shared && - s->exec_runtime->shared->userns_storage_socket[0] >= 0) { - r = open_shareable_ns_path(s->exec_runtime->shared->userns_storage_socket, s->exec_context.user_namespace_path, CLONE_NEWUSER); - if (r < 0) - return log_unit_error_errno(UNIT(s), r, "Failed to open user namespace path %s: %m", s->exec_context.user_namespace_path); - } + if (s->exec_runtime && s->exec_runtime->shared) { + if (s->exec_context.user_namespace_path && + s->exec_runtime->shared->userns_storage_socket[0] >= 0) { + r = open_shareable_ns_path(s->exec_runtime->shared->userns_storage_socket, s->exec_context.user_namespace_path, CLONE_NEWUSER); + if (r < 0) + return log_unit_error_errno(UNIT(s), r, "Failed to open user namespace path %s: %m", s->exec_context.user_namespace_path); + } - if (s->exec_context.network_namespace_path && - s->exec_runtime && - s->exec_runtime->shared && - s->exec_runtime->shared->netns_storage_socket[0] >= 0) { - r = open_shareable_ns_path(s->exec_runtime->shared->netns_storage_socket, s->exec_context.network_namespace_path, CLONE_NEWNET); - if (r < 0) - return log_unit_error_errno(UNIT(s), r, "Failed to open network namespace path %s: %m", s->exec_context.network_namespace_path); - } + if (s->exec_context.network_namespace_path && + s->exec_runtime->shared->netns_storage_socket[0] >= 0) { + r = open_shareable_ns_path(s->exec_runtime->shared->netns_storage_socket, s->exec_context.network_namespace_path, CLONE_NEWNET); + if (r < 0) + return log_unit_error_errno(UNIT(s), r, "Failed to open network namespace path %s: %m", s->exec_context.network_namespace_path); + } - if (s->exec_context.ipc_namespace_path && - s->exec_runtime && - s->exec_runtime->shared && - s->exec_runtime->shared->ipcns_storage_socket[0] >= 0) { - r = open_shareable_ns_path(s->exec_runtime->shared->ipcns_storage_socket, s->exec_context.ipc_namespace_path, CLONE_NEWIPC); - if (r < 0) - return log_unit_error_errno(UNIT(s), r, "Failed to open IPC namespace path %s: %m", s->exec_context.ipc_namespace_path); + if (s->exec_context.ipc_namespace_path && + s->exec_runtime->shared->ipcns_storage_socket[0] >= 0) { + r = open_shareable_ns_path(s->exec_runtime->shared->ipcns_storage_socket, s->exec_context.ipc_namespace_path, CLONE_NEWIPC); + if (r < 0) + return log_unit_error_errno(UNIT(s), r, "Failed to open IPC namespace path %s: %m", s->exec_context.ipc_namespace_path); + } } if (socketpair(AF_UNIX, SOCK_SEQPACKET|SOCK_CLOEXEC, 0, pair) < 0) -- 2.47.3