From c32595491cb6118822b23aaaef196e018e7f6482 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Fri, 2 Feb 2024 01:23:56 +0000 Subject: [PATCH] start-stop-daemon: fix setting scheduler with musl 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: https://github.com/OpenRC/openrc/issues/689 --- src/start-stop-daemon/meson.build | 2 +- src/start-stop-daemon/start-stop-daemon.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/start-stop-daemon/meson.build b/src/start-stop-daemon/meson.build index 6cae791d9..13f92aaf3 100644 --- a/src/start-stop-daemon/meson.build +++ b/src/start-stop-daemon/meson.build @@ -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) diff --git a/src/start-stop-daemon/start-stop-daemon.c b/src/start-stop-daemon/start-stop-daemon.c index dda89a649..aa390d88b 100644 --- a/src/start-stop-daemon/start-stop-daemon.c +++ b/src/start-stop-daemon/start-stop-daemon.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -1126,7 +1127,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};