From 635067d44f221c4209f0e28940f02ea789bd43e3 Mon Sep 17 00:00:00 2001 From: jonnyh64 <60403537+jonnyh64@users.noreply.github.com> Date: Wed, 29 Jan 2020 22:24:16 +0100 Subject: [PATCH] chrt: Use sched_setscheduler system call directly musl libc does not support the sched_setscheduler library function because the underlying Linux system call does not confirm to Posix; this patch makes chrt use the system call directly [kzak@redhat.com: - note that musl libc implements sched_setscheduler() but returns -ENOSYS all time... - add ifdefs to the patch - make sure we include syscall.h] References: http://git.musl-libc.org/cgit/musl/commit/src/sched/sched_setscheduler.c?id=1e21e78bf7a5c24c217446d8760be7b7188711c2 Addresses: https://github.com/karelzak/util-linux/issues/943 Signed-off-by: Karel Zak --- schedutils/chrt.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/schedutils/chrt.c b/schedutils/chrt.c index cc3a8c2f0e..299c99221e 100644 --- a/schedutils/chrt.c +++ b/schedutils/chrt.c @@ -60,7 +60,7 @@ # define SCHED_FLAG_RESET_ON_FORK 0x01 #endif -#if defined (__linux__) && !defined(HAVE_SCHED_SETATTR) +#if defined (__linux__) # include #endif @@ -347,7 +347,16 @@ static int set_sched_one_by_setscheduler(struct chrt_ctl *ctl, pid_t pid) if (ctl->reset_on_fork) policy |= SCHED_RESET_ON_FORK; # endif + +#if defined (__linux__) && defined(SYS_sched_setscheduler) + /* musl libc returns ENOSYS for its sched_setscheduler library + * function, because the sched_setscheduler Linux kernel system call + * does not conform to Posix; so we use the system call directly + */ + return syscall(SYS_sched_setscheduler, pid, policy, &sp); +#else return sched_setscheduler(pid, policy, &sp); +#endif } -- 2.47.2