From: Mike Yuan Date: Wed, 31 Dec 2025 18:21:13 +0000 (+0100) Subject: core/exec-invoke: use RET_NERRNO to avoid clobbering errno X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d7bc1e3be9758395f7a119138b5bba79aaba70c8;p=thirdparty%2Fsystemd.git core/exec-invoke: use RET_NERRNO to avoid clobbering errno Follow-up for 72ce1046e8aa872af8edcfba407e6f0489662fda string_table_lookup_to_string_fallback() might interfere with errno, hence store it in r first. --- diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index cf47d996b29..34b03f366e2 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -5471,17 +5471,14 @@ int exec_invoke( .sched_flags = context->cpu_sched_reset_on_fork ? SCHED_FLAG_RESET_ON_FORK : 0, }; - r = sched_setattr(/* pid= */ 0, &attr, /* flags= */ 0); - if (r < 0) { - if (errno != EINVAL || sched_policy_supported(attr.sched_policy)) { - *exit_status = EXIT_SETSCHEDULER; - return log_error_errno(errno, "Failed to set up CPU scheduling: %m"); - } - + r = RET_NERRNO(sched_setattr(/* pid= */ 0, &attr, /* flags= */ 0)); + if (r == -EINVAL && !sched_policy_supported(context->cpu_sched_policy)) { _cleanup_free_ char *s = NULL; (void) sched_policy_to_string_alloc(context->cpu_sched_policy, &s); - - log_warning_errno(errno, "CPU scheduling policy %s is not supported, proceeding without.", strna(s)); + log_warning_errno(r, "CPU scheduling policy %s is not supported, proceeding without.", strna(s)); + } else if (r < 0) { + *exit_status = EXIT_SETSCHEDULER; + return log_error_errno(r, "Failed to set up CPU scheduling: %m"); } }