From: Mike Yuan Date: Tue, 6 Jan 2026 21:42:37 +0000 (+0100) Subject: core/exec-invoke: dedup error handling X-Git-Tag: v260-rc1~367^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a91bb7459ba6a3e88c2b25e093ca6d2cc12619ac;p=thirdparty%2Fsystemd.git core/exec-invoke: dedup error handling Also, do not log about errno if it's suffciently encoded in the log text already. --- diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index c8994c83340..ebacec7fd9a 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -4752,6 +4752,33 @@ static int setup_delegated_namespaces( return 0; } +static int set_memory_thp(MemoryTHP thp) { + int r; + + switch (thp) { + + case MEMORY_THP_INHERIT: + return 0; + + case MEMORY_THP_DISABLE: + r = RET_NERRNO(prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0)); + break; + + case MEMORY_THP_MADVISE: + r = RET_NERRNO(prctl(PR_SET_THP_DISABLE, 1, PR_THP_DISABLE_EXCEPT_ADVISED, 0, 0)); + break; + + case MEMORY_THP_SYSTEM: + r = RET_NERRNO(prctl(PR_SET_THP_DISABLE, 0, 0, 0, 0)); + break; + + default: + assert_not_reached(); + } + + return r == -EINVAL ? -EOPNOTSUPP : r; +} + static bool exec_context_shall_confirm_spawn(const ExecContext *context) { assert(context); @@ -4868,32 +4895,6 @@ static int exec_fd_mark_hot( return 1; } -static int set_memory_thp(MemoryTHP thp) { - switch (thp) { - - case MEMORY_THP_INHERIT: - return 0; - - case MEMORY_THP_DISABLE: - if (prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0) < 0) - return errno == EINVAL ? -EOPNOTSUPP : -errno; - return 0; - - case MEMORY_THP_MADVISE: - if (prctl(PR_SET_THP_DISABLE, 1, PR_THP_DISABLE_EXCEPT_ADVISED, 0, 0) < 0) - return errno == EINVAL ? -EOPNOTSUPP : -errno; - return 0; - - case MEMORY_THP_SYSTEM: - if (prctl(PR_SET_THP_DISABLE, 0, 0, 0, 0) < 0) - return errno == EINVAL ? -EOPNOTSUPP : -errno; - return 0; - - default: - assert_not_reached(); - } -} - static int send_handoff_timestamp( const ExecContext *c, ExecParameters *p, @@ -5580,7 +5581,7 @@ int exec_invoke( r = set_memory_thp(context->memory_thp); if (r == -EOPNOTSUPP) - log_debug_errno(r, "Setting MemoryTHP=%s is not supported, ignoring: %m", + log_debug_errno(r, "Setting MemoryTHP=%s is not supported, ignoring.", memory_thp_to_string(context->memory_thp)); else if (r < 0) { *exit_status = EXIT_MEMORY_THP;