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 everywhere so we don't depend on any
implementation specific behavior.

ref: https://www.openwall.com/lists/musl/2016/03/01/5
fixes: #689
  • Loading branch information
ncopa committed Feb 15, 2024
1 parent c45fe9f commit 2020c57
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/start-stop-daemon/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ executable('start-stop-daemon',
selinux_c, usage_c, version_h],
c_args : [cc_audit_flags, cc_branding_flags, cc_pam_flags, cc_cap_flags, cc_selinux_flags],
link_with: [libeinfo, librc],
dependencies: [audit_dep, dl_dep, pam_dep, cap_dep, pam_misc_dep, util_dep, selinux_dep, crypt_dep],
dependencies: [audit_dep, dl_dep, pam_dep, cap_dep, pam_misc_dep, util_dep, selinux_dep, crypt_dep, dependency('threads')],
include_directories: [incdir, einfo_incdir, rc_incdir],
install: true,
install_dir: sbindir)
Expand Down
3 changes: 2 additions & 1 deletion 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,7 @@ int main(int argc, char **argv)
if (sched_prio == -1)
sched.sched_priority = sched_get_priority_min(scheduler_index);

if (sched_setscheduler(mypid, scheduler_index, &sched))
if (pthread_setschedparam(pthread_self(), scheduler_index, &sched))
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 2020c57

Please sign in to comment.