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>
}
}
+#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 };
}
-#ifndef HAVE_SCHED_SETATTR
static int set_sched_one(struct chrt_ctl *ctl, pid_t pid)
{
return set_sched_one_by_setscheduler(ctl, 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);