From 0ea00396fd2cb017d4866c82072fe6883f06daaa Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Tue, 18 Feb 2025 12:25:16 +0100 Subject: [PATCH] exec-invoke: Move KSM logic up Let's move it up to be located together with other resource logic instead of having it stuffed inbetween the sandboxing logic. --- src/core/exec-invoke.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index 10f425139bf..47a4141b01e 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -4864,6 +4864,19 @@ int exec_invoke( } } + if (context->memory_ksm >= 0) + if (prctl(PR_SET_MEMORY_MERGE, context->memory_ksm, 0, 0, 0) < 0) { + if (ERRNO_IS_NOT_SUPPORTED(errno)) + log_exec_debug_errno(context, + params, + errno, + "KSM support not available, ignoring."); + else { + *exit_status = EXIT_KSM; + return log_exec_error_errno(context, params, errno, "Failed to set KSM: %m"); + } + } + #if ENABLE_UTMP if (context->utmp_id) { _cleanup_free_ char *username_alloc = NULL; @@ -5247,19 +5260,6 @@ int exec_invoke( return r; } - if (context->memory_ksm >= 0) - if (prctl(PR_SET_MEMORY_MERGE, context->memory_ksm, 0, 0, 0) < 0) { - if (ERRNO_IS_NOT_SUPPORTED(errno)) - log_exec_debug_errno(context, - params, - errno, - "KSM support not available, ignoring."); - else { - *exit_status = EXIT_KSM; - return log_exec_error_errno(context, params, errno, "Failed to set KSM: %m"); - } - } - /* Drop groups as early as possible. * This needs to be done after PrivateDevices=yes setup as device nodes should be owned by the host's root. * For non-root in a userns, devices will be owned by the user/group before the group change, and nobody. */ -- 2.47.3