From: Dmitry V. Levin Date: Fri, 14 Jul 2023 08:00:00 +0000 (+0000) Subject: execute: cleanup use of ERRNO_IS_PRIVILEGE() X-Git-Tag: v255-rc1~886^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5cf4c468a4c3f84b0fa55a5658a9404f3d0653b1;p=thirdparty%2Fsystemd.git execute: cleanup use of ERRNO_IS_PRIVILEGE() Given that ERRNO_IS_PRIVILEGE() also matches positive values, make sure this macro is not called with arguments that do not have errno semantics. In this case the arguments passed to ERRNO_IS_PRIVILEGE() are the values returned by set_oom_score_adjust() and set_coredump_filter() which are not expected to return any positive values, but let's be consistent anyway and move the ERRNO_IS_PRIVILEGE() invocations to the branches where the return values are known to be negative. --- diff --git a/src/core/execute.c b/src/core/execute.c index 9dafdffa08f..07913e658b3 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -5098,20 +5098,24 @@ static int exec_child( /* When we can't make this change due to EPERM, then let's silently skip over it. User namespaces * prohibit write access to this file, and we shouldn't trip up over that. */ r = set_oom_score_adjust(context->oom_score_adjust); - if (ERRNO_IS_PRIVILEGE(r)) - log_unit_debug_errno(unit, r, "Failed to adjust OOM setting, assuming containerized execution, ignoring: %m"); - else if (r < 0) { - *exit_status = EXIT_OOM_ADJUST; - return log_unit_error_errno(unit, r, "Failed to adjust OOM setting: %m"); + if (r < 0) { + if (ERRNO_IS_PRIVILEGE(r)) + log_unit_debug_errno(unit, r, "Failed to adjust OOM setting, assuming containerized execution, ignoring: %m"); + else { + *exit_status = EXIT_OOM_ADJUST; + return log_unit_error_errno(unit, r, "Failed to adjust OOM setting: %m"); + } } } if (context->coredump_filter_set) { r = set_coredump_filter(context->coredump_filter); - if (ERRNO_IS_PRIVILEGE(r)) - log_unit_debug_errno(unit, r, "Failed to adjust coredump_filter, ignoring: %m"); - else if (r < 0) - return log_unit_error_errno(unit, r, "Failed to adjust coredump_filter: %m"); + if (r < 0) { + if (ERRNO_IS_PRIVILEGE(r)) + log_unit_debug_errno(unit, r, "Failed to adjust coredump_filter, ignoring: %m"); + else + return log_unit_error_errno(unit, r, "Failed to adjust coredump_filter: %m"); + } } if (context->nice_set) {