Provide thin stubs for the sched_getscheduler() and sched_getscheduler()
syscalls, as musl has dropped their implementation. The thin stubs are exactly
what glibc does and what rtkit expects.
--- rtkit-0.13.orig/rtkit-daemon.c
+++ rtkit-0.13/rtkit-daemon.c
@@ -32,6 +32,7 @@
 #include <sys/stat.h>
 #include <string.h>
 #include <sched.h>
+#include <syscall.h>
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <stdlib.h>
@@ -196,6 +197,14 @@
 static pthread_t canary_thread_id = 0, watchdog_thread_id = 0;
 static volatile uint32_t refuse_until = 0;
 
+static int _sched_setscheduler(pid_t pid, int sched, const struct sched_param *param) {
+        return syscall(SYS_sched_setscheduler, pid, sched, param);
+}
+
+static int _sched_getscheduler(pid_t pid) {
+        return syscall(SYS_sched_getscheduler, pid);
+}
+
 static const char *get_proc_path(void) {
         /* Useful for chroot environments */
 
@@ -439,7 +448,7 @@
         if (st != t->starttime)
                 return FALSE;
 
-        if ((r = sched_getscheduler(t->pid)) < 0) {
+        if ((r = _sched_getscheduler(t->pid)) < 0) {
 
                 /* Maybe it died right now? */
                 if (errno == ESRCH)
@@ -564,7 +573,7 @@
         memset(&param, 0, sizeof(param));
         param.sched_priority = priority;
 
-        if (sched_setscheduler(0, sched_policy|SCHED_RESET_ON_FORK, &param) < 0) {
+        if (_sched_setscheduler(0, sched_policy|SCHED_RESET_ON_FORK, &param) < 0) {
                 r = -errno;
                 syslog(LOG_ERR, "Failed to make ourselves RT: %s\n", strerror(errno));
                 goto finish;
@@ -581,7 +590,7 @@
 
         memset(&param, 0, sizeof(param));
 
-        if (sched_setscheduler(0, SCHED_OTHER, &param) < 0)
+        if (_sched_setscheduler(0, SCHED_OTHER, &param) < 0)
                 syslog(LOG_WARNING, "Warning: Failed to reset scheduling to SCHED_OTHER: %s\n", strerror(errno));
 
         if (setpriority(PRIO_PROCESS, 0, nice_level) < 0)
@@ -696,7 +705,7 @@
         memset(&param, 0, sizeof(param));
         param.sched_priority = 0;
 
-        if (sched_setscheduler(tid, SCHED_OTHER, &param) < 0) {
+        if (_sched_setscheduler(tid, SCHED_OTHER, &param) < 0) {
                 if (errno != ESRCH)
                         syslog(LOG_WARNING, "Warning: Failed to reset scheduling to SCHED_OTHER for thread %llu: %s\n", (unsigned long long) tid, strerror(errno));
                 r = -1;
@@ -748,7 +757,7 @@
         /* Ok, everything seems to be in order, now, let's do it */
         memset(&param, 0, sizeof(param));
         param.sched_priority = (int) priority;
-        if (sched_setscheduler(t->pid, sched_policy|SCHED_RESET_ON_FORK, &param) < 0) {
+        if (_sched_setscheduler(t->pid, sched_policy|SCHED_RESET_ON_FORK, &param) < 0) {
                 r = -errno;
                 syslog(LOG_ERR, "Failed to make thread %llu RT: %s\n", (unsigned long long) t->pid, strerror(errno));
                 goto finish;
@@ -809,7 +818,7 @@
         /* Ok, everything seems to be in order, now, let's do it */
         memset(&param, 0, sizeof(param));
         param.sched_priority = 0;
-        if (sched_setscheduler(t->pid, SCHED_OTHER|SCHED_RESET_ON_FORK, &param) < 0) {
+        if (_sched_setscheduler(t->pid, SCHED_OTHER|SCHED_RESET_ON_FORK, &param) < 0) {
                 r = -errno;
                 syslog(LOG_ERR, "Failed to make process %llu SCHED_NORMAL: %s\n", (unsigned long long) t->pid, strerror(errno));
                 goto finish;
@@ -943,7 +952,7 @@
                         if (errno != 0 || !e || *e != 0)
                                 continue;
 
-                        if ((r = sched_getscheduler(tid)) < 0) {
+                        if ((r = _sched_getscheduler(tid)) < 0) {
                                 if (errno != ESRCH)
                                         syslog(LOG_WARNING, "Warning: sched_getscheduler() failed: %s\n", strerror(errno));
                                 continue;
