use crate::process_unix::Inheritance;
use std::os::fd::RawFd;
pub trait SanitizeDescriptors {
fn sanitize_descriptors(&mut self, keep: &[RawFd]) -> &mut Self;
fn refresh_sanitized(&mut self) -> &mut Self;
}
impl SanitizeDescriptors for std::process::Command {
fn sanitize_descriptors(&mut self, keep: &[RawFd]) -> &mut Self {
use std::os::unix::process::CommandExt;
let inheritance = Inheritance::unchecked(keep.to_vec());
unsafe {
self.pre_exec(move || inheritance.apply());
}
self
}
fn refresh_sanitized(&mut self) -> &mut Self {
crate::process_unix::refresh_shared_bound();
self
}
}
#[cfg(feature = "tokio")]
impl SanitizeDescriptors for tokio::process::Command {
fn sanitize_descriptors(&mut self, keep: &[RawFd]) -> &mut Self {
let inheritance = Inheritance::unchecked(keep.to_vec());
unsafe {
self.pre_exec(move || inheritance.apply());
}
self
}
fn refresh_sanitized(&mut self) -> &mut Self {
crate::process_unix::refresh_shared_bound();
self
}
}