From: Karel Zak Date: Tue, 26 May 2026 10:21:49 +0000 (+0200) Subject: chrt: always use sched_setattr() for all policies X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=ad713be7ba98f781de57cb10a607c04687dbdf48;p=thirdparty%2Futil-linux.git chrt: always use sched_setattr() for all policies 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 --- diff --git a/schedutils/chrt.c b/schedutils/chrt.c index f968b2696..9cc5a7f77 100644 --- a/schedutils/chrt.c +++ b/schedutils/chrt.c @@ -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);