use std::io;
use crate::platform::process::{
OwnerDeathCleanup, OwnerDeathCleanupError, OwnerDeathCleanupStage,
};
pub fn install_owner_death_cleanup() -> Result<OwnerDeathCleanup, OwnerDeathCleanupError> {
let rc = unsafe { libc::prctl(libc::PR_SET_PDEATHSIG, libc::SIGTERM) };
if rc == -1 {
return Err(OwnerDeathCleanupError {
stage: OwnerDeathCleanupStage::RequestSignal,
source: io::Error::last_os_error(),
});
}
Ok(OwnerDeathCleanup::OwnerDeathSignal)
}
pub fn owner_death_cleanup_target() -> OwnerDeathCleanup {
OwnerDeathCleanup::OwnerDeathSignal
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn linux_parent_death_signal_is_sigterm() {
assert_eq!(libc::SIGTERM, 15, "SIGTERM is 15 on every Linux ABI we build for");
}
#[test]
fn the_target_matches_what_installing_reports() {
assert_eq!(
owner_death_cleanup_target(),
install_owner_death_cleanup().expect("prctl is available to any process"),
);
}
}