pub fn confine_children() {
#[cfg(windows)]
imp::confine();
}
#[cfg(windows)]
mod imp {
use tracing::{info, warn};
use win32job::{ExtendedLimitInfo, Job};
pub fn confine() {
let mut info = ExtendedLimitInfo::new();
info.limit_kill_on_job_close();
let job = match Job::create_with_limit_info(&info) {
Ok(job) => job,
Err(err) => {
warn!(
"could not create the job object to confine backup children ({err}); \
they may outlive a daemon restart"
);
return;
}
};
if let Err(err) = job.assign_current_process() {
warn!(
"could not assign the daemon to its job object ({err}); \
backup children may outlive a daemon restart"
);
return;
}
let _ = job.into_handle();
info!("confined child processes to the daemon's lifetime");
}
}