]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/exec-invoke: use RET_NERRNO to avoid clobbering errno
authorMike Yuan <me@yhndnzj.com>
Wed, 31 Dec 2025 18:21:13 +0000 (19:21 +0100)
committerMike Yuan <me@yhndnzj.com>
Wed, 31 Dec 2025 18:32:58 +0000 (19:32 +0100)
Follow-up for 72ce1046e8aa872af8edcfba407e6f0489662fda

string_table_lookup_to_string_fallback() might interfere
with errno, hence store it in r first.

src/core/exec-invoke.c

index cf47d996b29a67bee117ca9590f9b36ed31ccfa2..34b03f366e27ece3465fd4c8df0eb52a1e2c9b66 100644 (file)
@@ -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");
                 }
         }