mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-30 12:49:40 +00:00
ptp-helper: Set a process priority / nice value of -5 on UNIX platforms
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3889>
This commit is contained in:
parent
572d344482
commit
9d25a5075e
3 changed files with 25 additions and 2 deletions
|
@ -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"))]
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue