]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
chrt: always use sched_setattr() for all policies
authorKarel Zak <kzak@redhat.com>
Tue, 26 May 2026 10:21:49 +0000 (12:21 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 26 May 2026 10:21:49 +0000 (12:21 +0200)
Remove the set_sched_one_by_setscheduler() shortcut for non-deadline
policies from the HAVE_SCHED_SETATTR code path. The original reason
(2016, commit 88b60f0bdee6) was that sched_setattr() reset the nice
value, causing EPERM for non-root users. But getpriority() already
preserves the nice setting, making the shortcut unnecessary.

The shortcut caused --clamp-min/--clamp-max (SCHED_FLAG_UTIL_CLAMP)
to be silently ignored for SCHED_FIFO and SCHED_RR, because those
policies were routed through sched_setscheduler() which cannot pass
sched_flags at all.

Using sched_setattr() unconditionally ensures all sched_flags work
with all policies and prevents the same class of bug for future flag
additions.

Addresses: https://github.com/util-linux/util-linux/pull/4351
Signed-off-by: Karel Zak <kzak@redhat.com>
schedutils/chrt.c

index f968b269673b923a28a1ba73f473a83781ffbb68..9cc5a7f77a2b14d9937b81a0919b68b99220e324 100644 (file)
@@ -350,6 +350,7 @@ static void show_min_max(void)
        }
 }
 
+#ifndef HAVE_SCHED_SETATTR
 static int set_sched_one_by_setscheduler(struct chrt_ctl *ctl, pid_t pid)
 {
        struct sched_param sp = { .sched_priority = ctl->priority };
@@ -373,7 +374,6 @@ static int set_sched_one_by_setscheduler(struct chrt_ctl *ctl, pid_t pid)
 }
 
 
-#ifndef HAVE_SCHED_SETATTR
 static int set_sched_one(struct chrt_ctl *ctl, pid_t pid)
 {
        return set_sched_one_by_setscheduler(ctl, pid);
@@ -385,10 +385,6 @@ static int set_sched_one(struct chrt_ctl *ctl, pid_t pid)
        struct sched_attr sa = { .size = sizeof(struct sched_attr) };
        int ret;
 
-       /* old API is good enough for non-deadline */
-       if (!supports_runtime_param(ctl->policy))
-               return set_sched_one_by_setscheduler(ctl, pid);
-
        /* not changed by chrt, follow the current setting */
        sa.sched_nice = getpriority(PRIO_PROCESS, pid);