use std::time::Duration;
use super::Process;
use crate::error::Error;
impl Process {
pub fn terminate(&self) -> Result<(), Error> {
crate::os_process::terminate(&*self.os)
}
pub fn graceful_shutdown(&self, grace: Duration) -> Result<(), Error> {
self.terminate()?;
#[cfg(test)]
crate::graceful_hooks::run_hook(crate::graceful_hooks::HookPoint::AfterTerminate);
crate::graceful::after_grace(self.wait_timeout(grace), || self.kill())
}
pub fn kill_tree(&self) -> Result<(), Error> {
self.kill_tree_with(&crate::identity::HostKernel)
}
pub(crate) fn kill_tree_with(&self, kernel: &dyn crate::identity::Kernel) -> Result<(), Error> {
crate::containment::treewalk::hard_kill(kernel, self.id)
.into_result()
.or_else(|left| left.unsettled(false))
.map_err(|left| left.report("Process::kill_tree"))
}
pub fn terminate_tree(&self) -> Result<(), Error> {
self.terminate_tree_with(&crate::identity::HostKernel)
}
pub(crate) fn terminate_tree_with(&self, kernel: &dyn crate::identity::Kernel) -> Result<(), Error> {
#[cfg(unix)]
{
crate::containment::treewalk::terminate(kernel, self.id)
}
#[cfg(windows)]
{
let _ = (kernel, self.id);
Err(Error::Unsupported {
op: "foreign tree graceful terminate".into(),
platform: "windows",
detail: "Windows has no per-process graceful signal, and a foreign process \
shares no addressable process group with us; use kill_tree for a hard \
identity-walk sweep"
.into(),
})
}
#[cfg(not(any(unix, windows)))]
{
let _ = (kernel, self.id);
Ok(())
}
}
pub fn graceful_shutdown_tree(&self, grace: Duration) -> Result<(), Error> {
self.terminate_tree()?; #[cfg(test)]
crate::graceful_hooks::run_hook(crate::graceful_hooks::HookPoint::AfterTerminate);
crate::graceful::after_tree_grace(self.wait_timeout(grace), || self.kill_tree())
}
}
#[cfg(test)]
#[path = "graceful_tests.rs"]
mod graceful_tests;