From 833fb23fe8b485d5bb4544c10b9e5577b2c51982 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 13 Nov 2018 17:22:37 -0600 Subject: Instead of #warning about the musl bug, work around it (wrap syscalls ourselves) --- toys/other/chrt.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'toys') diff --git a/toys/other/chrt.c b/toys/other/chrt.c index a1c37a05..618de84d 100644 --- a/toys/other/chrt.c +++ b/toys/other/chrt.c @@ -28,11 +28,24 @@ config CHRT #include "toys.h" GLOBALS( - long pid; + long p; ) #ifndef _POSIX_PRIORITY_SCHEDULING -#warning "musl-libc intentionally broke sched_get_priority_min() and friends in commit 1e21e78bf7a5 because its maintainer didn't like those Linux system calls" +// musl-libc intentionally broke sched_get_priority_min() and friends in +// commit 1e21e78bf7a5 because its maintainer didn't like those Linux +// system calls, so work around it here. +#include +#define sched_get_priority_min(policy) \ + (int)syscall(SYS_sched_get_priority_min, (int)policy) +#define sched_get_priority_max(policy) \ + (int)syscall(SYS_sched_get_priority_max, (int)policy) +#define sched_getparam(pid, param) \ + syscall(SYS_sched_getparam, (pid_t)pid, (void *)param) +#define sched_getscheduler(pid) \ + syscall(SYS_sched_getscheduler, (pid_t)pid) +#define sched_setscheduler(pid, scheduler, param) \ + syscall(SYS_sched_setscheduler, (pid_t)pid, (int)scheduler, (void *)param) #endif char *polnames[] = { @@ -57,13 +70,13 @@ void chrt_main(void) if (toys.optflags==FLAG_p && !*toys.optargs) { char *s = "???", *R = ""; - if (-1==(pol = sched_getscheduler(TT.pid))) perror_exit("pid %ld", TT.pid); + if (-1==(pol = sched_getscheduler(TT.p))) perror_exit("pid %ld", TT.p); if (pol & SCHED_RESET_ON_FORK) R = "|SCHED_RESET_ON_FORK"; if ((pol &= ~SCHED_RESET_ON_FORK)