From 43602911c6512da834673e1c0f7fb2cfad466eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fukan=20Korkmazt=C3=BCrk?= Date: Wed, 13 Jul 2022 08:09:32 -0400 Subject: [PATCH] module-rt: handle pthread_getschedparam() errors correctly pthread_getschedparam() always returns non-negative values, so checking if its return value is less than zero always evaluates to false. Also, pthread functions don't set errno. While logging a warning message, use the return value of pthread_getschedparam() instead of errno. --- src/modules/module-rt.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/modules/module-rt.c b/src/modules/module-rt.c index 869d5c08e..ca71775d7 100644 --- a/src/modules/module-rt.c +++ b/src/modules/module-rt.c @@ -520,9 +520,8 @@ static const struct pw_impl_module_events module_events = { */ static bool check_realtime_privileges(rlim_t priority) { - int old_policy; + int err, old_policy, new_policy = REALTIME_POLICY; struct sched_param old_sched_params; - int new_policy = REALTIME_POLICY; struct sched_param new_sched_params; /* We could check `RLIMIT_RTPRIO`, but the BSDs generally don't have @@ -530,8 +529,8 @@ static bool check_realtime_privileges(rlim_t priority) * scheduling without that rlimit being set such as `CAP_SYS_NICE` or * running as root. Instead of checking a bunch of preconditions, we * just try if setting realtime scheduling works or not. */ - if (pthread_getschedparam(pthread_self(),&old_policy,&old_sched_params) < 0) { - pw_log_warn("Failed to check RLIMIT_RTPRIO %m"); + if ((err = pthread_getschedparam(pthread_self(),&old_policy,&old_sched_params)) != 0) { + pw_log_warn("Failed to check RLIMIT_RTPRIO: %s", strerror(err)); return false; }