]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
chrt: Use sched_setscheduler system call directly
authorjonnyh64 <60403537+jonnyh64@users.noreply.github.com>
Wed, 29 Jan 2020 21:24:16 +0000 (22:24 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 30 Jan 2020 09:45:32 +0000 (10:45 +0100)
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 <kzak@redhat.com>
schedutils/chrt.c

index cc3a8c2f0e8945be43b487c046c051b3c9107cfb..299c99221ecce4bc81ce0eb5778c2d49db4eb820 100644 (file)
@@ -60,7 +60,7 @@
 # define SCHED_FLAG_RESET_ON_FORK 0x01
 #endif
 
-#if defined (__linux__) && !defined(HAVE_SCHED_SETATTR)
+#if defined (__linux__)
 # include <sys/syscall.h>
 #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
 }