use log::debug;
use nix::{
errno::Errno,
libc::{self, c_ulong},
sys::signal::Signal,
};
pub fn set_parent_death_signal(signal: Signal) {
#[cfg(target_os = "android")]
const PR_SET_PDEATHSIG: libc::c_int = 1;
#[cfg(not(target_os = "android"))]
use libc::PR_SET_PDEATHSIG;
debug!("Setting parent death signal to {}", signal);
let result = unsafe { nix::libc::prctl(PR_SET_PDEATHSIG, signal, 0, 0, 0) };
Errno::result(result)
.map(drop)
.expect("failed to set PR_SET_PDEATHSIG");
}
pub fn set_process_name(name: &str) {
#[cfg(target_os = "android")]
const PR_SET_NAME: libc::c_int = 15;
#[cfg(not(target_os = "android"))]
use libc::PR_SET_NAME;
debug!("Setting process name to {}", name);
let mut name = name.as_bytes().to_vec();
name.truncate(15);
name.push(b'\0');
let result = unsafe { libc::prctl(PR_SET_NAME, name.as_ptr() as c_ulong, 0, 0, 0) };
Errno::result(result)
.map(drop)
.expect("failed to set PR_SET_NAME");
}
pub fn set_child_subreaper(value: bool) {
#[cfg(target_os = "android")]
const PR_SET_CHILD_SUBREAPER: nix::libc::c_int = 36;
#[cfg(not(target_os = "android"))]
use nix::libc::PR_SET_CHILD_SUBREAPER;
debug!("Setting child subreaper flag to {}", value);
let value = u64::from(value);
let result = unsafe { nix::libc::prctl(PR_SET_CHILD_SUBREAPER, value, 0, 0, 0) };
Errno::result(result)
.map(drop)
.expect("failed to set child subreaper flag")
}