diff --git a/subprojects/gstreamer/libs/gst/helpers/ptp/ffi.rs b/subprojects/gstreamer/libs/gst/helpers/ptp/ffi.rs index 0988765626..7b3ca372db 100644 --- a/subprojects/gstreamer/libs/gst/helpers/ptp/ffi.rs +++ b/subprojects/gstreamer/libs/gst/helpers/ptp/ffi.rs @@ -178,6 +178,8 @@ pub mod unix { #[cfg(not(any(target_os = "linux", target_os = "solaris", target_os = "illumos")))] pub const IF_NAMESIZE: usize = 16; + pub const PRIO_PROCESS: c_int = 0; + extern "C" { #[cfg_attr( all(target_os = "macos", target_arch = "x86"), @@ -220,6 +222,8 @@ pub mod unix { pub fn getifaddrs(ifap: *mut *mut ifaddrs) -> c_int; pub fn freeifaddrs(ifa: *mut ifaddrs); + + pub fn setpriority(which: c_int, who: c_int, prio: c_int) -> c_int; } #[cfg(any(target_os = "linux", target_os = "solaris", target_os = "illumos"))] diff --git a/subprojects/gstreamer/libs/gst/helpers/ptp/ptp_helper_post_install.sh b/subprojects/gstreamer/libs/gst/helpers/ptp/ptp_helper_post_install.sh index 4370acd956..2ed427ed01 100755 --- a/subprojects/gstreamer/libs/gst/helpers/ptp/ptp_helper_post_install.sh +++ b/subprojects/gstreamer/libs/gst/helpers/ptp/ptp_helper_post_install.sh @@ -17,8 +17,8 @@ case "$with_ptp_helper_permissions" in ls -l "$ptp_helper" ;; capabilities) - echo "Calling $setcap cap_net_bind_service,cap_net_admin+ep $ptp_helper" - $setcap cap_net_bind_service,cap_net_admin+ep "$ptp_helper" || true + echo "Calling $setcap cap_sys_nice,cap_net_bind_service,cap_net_admin+ep $ptp_helper" + $setcap cap_sys_nice,cap_net_bind_service,cap_net_admin+ep "$ptp_helper" || true ;; none) echo "No perms/caps to set for $ptp_helper" diff --git a/subprojects/gstreamer/libs/gst/helpers/ptp/thread.rs b/subprojects/gstreamer/libs/gst/helpers/ptp/thread.rs index 9577e7e38d..eff363d600 100644 --- a/subprojects/gstreamer/libs/gst/helpers/ptp/thread.rs +++ b/subprojects/gstreamer/libs/gst/helpers/ptp/thread.rs @@ -11,6 +11,25 @@ use crate::error::Error; pub fn set_priority() -> Result<(), Error> { + #[cfg(unix)] + { + use std::io; + + use crate::{bail, ffi::unix::*}; + + // SAFETY: Setting the process priority can happen at any time. A negative + // priority require special permissions, which should've been given to the process. + // + // On error it returns a negative value. + unsafe { + if setpriority(PRIO_PROCESS, 0, -5) < 0 { + bail!( + source: io::Error::last_os_error(), + "Failed to set process priority" + ); + } + } + } #[cfg(windows)] { use std::io;