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
@ -178,6 +178,8 @@ pub mod unix {
|
|||||||
#[cfg(not(any(target_os = "linux", target_os = "solaris", target_os = "illumos")))]
|
#[cfg(not(any(target_os = "linux", target_os = "solaris", target_os = "illumos")))]
|
||||||
pub const IF_NAMESIZE: usize = 16;
|
pub const IF_NAMESIZE: usize = 16;
|
||||||
|
|
||||||
|
pub const PRIO_PROCESS: c_int = 0;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
all(target_os = "macos", target_arch = "x86"),
|
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 getifaddrs(ifap: *mut *mut ifaddrs) -> c_int;
|
||||||
pub fn freeifaddrs(ifa: *mut ifaddrs);
|
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"))]
|
#[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"
|
ls -l "$ptp_helper"
|
||||||
;;
|
;;
|
||||||
capabilities)
|
capabilities)
|
||||||
echo "Calling $setcap cap_net_bind_service,cap_net_admin+ep $ptp_helper"
|
echo "Calling $setcap cap_sys_nice,cap_net_bind_service,cap_net_admin+ep $ptp_helper"
|
||||||
$setcap cap_net_bind_service,cap_net_admin+ep "$ptp_helper" || true
|
$setcap cap_sys_nice,cap_net_bind_service,cap_net_admin+ep "$ptp_helper" || true
|
||||||
;;
|
;;
|
||||||
none)
|
none)
|
||||||
echo "No perms/caps to set for $ptp_helper"
|
echo "No perms/caps to set for $ptp_helper"
|
||||||
|
@ -11,6 +11,25 @@
|
|||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
|
|
||||||
pub fn set_priority() -> Result<(), 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)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
use std::io;
|
use std::io;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user