Skip to content

Commit

Permalink
start-stop-daemon: fix setting scheduler with musl
Browse files Browse the repository at this point in the history
Linux does not provide a way to set scheduling parameters for a process,
only for threads, so musl sched_setscheduler() is only a stub and the
glibc implementation does "the wrong thing".

Use pthread_setschedparam instead for Linux.

ref: https://www.openwall.com/lists/musl/2016/03/01/5
fixes: #689
  • Loading branch information
ncopa committed Feb 2, 2024
1 parent c45fe9f commit 54e787a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/start-stop-daemon/start-stop-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <getopt.h>
#include <limits.h>
#include <grp.h>
#include <pthread.h>
#include <pwd.h>
#include <sched.h>
#include <signal.h>
Expand Down Expand Up @@ -1123,7 +1124,11 @@ int main(int argc, char **argv)
if (sched_prio == -1)
sched.sched_priority = sched_get_priority_min(scheduler_index);

#ifdef __linux__
if (pthread_setschedparam(pthread_self(), scheduler_index, &sched))
#else
if (sched_setscheduler(mypid, scheduler_index, &sched))
#endif
eerrorx("Failed to set scheduler: %s", strerror(errno));
} else if (sched_prio != -1) {
const struct sched_param sched = {.sched_priority = sched_prio};
Expand Down

0 comments on commit 54e787a

Please sign in to comment.