use rustix::process::Signal;
use std::os::unix::process::CommandExt as _;
use std::process::Command;
pub trait WithPdeathsig {
fn with_pdeathsig(&mut self, signal: Option<Signal>) -> &mut Self;
}
impl WithPdeathsig for Command {
fn with_pdeathsig(&mut self, signal: Option<Signal>) -> &mut Self {
let parent_pid = rustix::process::getpid();
let pre_exec = move || -> std::io::Result<()> {
rustix::process::set_parent_process_death_signal(signal)?;
assert!(
Some(parent_pid) == rustix::process::getppid(),
"Parent already dead"
);
Ok(())
};
unsafe { self.pre_exec(pre_exec) }
}
}