mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
module-rt: Don't explicitly check RLIMIT_RTPRIO
There are a couple other ways to allow a user/process to use realtime priviliges like `CAP_SYS_NICE`. Instead of trying to check every possible factor, just trying if setting realtime priviliges works is going to be a much cleaner solution.
This commit is contained in:
parent
5b3bc4e80e
commit
e60f62e69b
1 changed files with 7 additions and 15 deletions
|
|
@ -480,20 +480,13 @@ static const struct pw_impl_module_events module_events = {
|
||||||
* Check if the current user has permissions to use realtime scheduling at the
|
* Check if the current user has permissions to use realtime scheduling at the
|
||||||
* specified priority.
|
* specified priority.
|
||||||
*/
|
*/
|
||||||
static bool check_rtprio_rlimit(rlim_t priority)
|
static bool check_realtime_priviliges(rlim_t priority)
|
||||||
{
|
{
|
||||||
#ifdef RLIMIT_RTPRIO
|
/* We could check `RLIMIT_RTPRIO`, but the BSDs generally don't have
|
||||||
struct rlimit limits;
|
* that available, and there are also other ways to use realtime
|
||||||
if (getrlimit(RLIMIT_RTPRIO, &limits) == 0 && (limits.rlim_cur >= priority || limits.rlim_cur == RLIM_INFINITY)) {
|
* scheduling without that rlimit being set such as `CAP_SYS_NICE` or
|
||||||
return true;
|
* running as root. Instead of checking a bunch of preconditions, we
|
||||||
} else {
|
* just try if setting realtime scheduling works or not. */
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
/* The BSDs generally don't have RLIMIT_RTPRIO. In that case we can just
|
|
||||||
* try if setting realtime scheduling works so it can still be used when
|
|
||||||
* PipeWire is run as root. There's probably a cleaner way to check this
|
|
||||||
* on FreeBSD that I'm now aware of. */
|
|
||||||
int old_scheduler;
|
int old_scheduler;
|
||||||
struct sched_param old_sched_params;
|
struct sched_param old_sched_params;
|
||||||
if ((old_scheduler = sched_getscheduler(0)) != 0 ||
|
if ((old_scheduler = sched_getscheduler(0)) != 0 ||
|
||||||
|
|
@ -510,7 +503,6 @@ static bool check_rtprio_rlimit(rlim_t priority)
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int set_nice(struct impl *impl, int nice_level)
|
static int set_nice(struct impl *impl, int nice_level)
|
||||||
|
|
@ -801,7 +793,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
||||||
|
|
||||||
/* If the user has permissions to use regular realtime scheduling, then
|
/* If the user has permissions to use regular realtime scheduling, then
|
||||||
* we'll use that instead of RTKit */
|
* we'll use that instead of RTKit */
|
||||||
if (check_rtprio_rlimit(impl->rt_prio)) {
|
if (check_realtime_priviliges(impl->rt_prio)) {
|
||||||
use_rtkit = false;
|
use_rtkit = false;
|
||||||
} else {
|
} else {
|
||||||
if (!use_rtkit) {
|
if (!use_rtkit) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue