Handle signalling to sub process on non-unix

This commit is contained in:
Félix Saparelli 2021-10-16 01:21:52 +13:00
parent 92513a4dc3
commit e577b040b9
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
4 changed files with 47 additions and 39 deletions

View File

@ -12,8 +12,6 @@ use tokio::{
}; };
use tracing::{debug, trace, warn}; use tracing::{debug, trace, warn};
pub use command_group::Signal;
use crate::{ use crate::{
command::Supervisor, command::Supervisor,
error::{CriticalError, RuntimeError}, error::{CriticalError, RuntimeError},
@ -232,10 +230,18 @@ async fn apply_outcome(
} }
(Some(p), Outcome::Signal(sig)) => { (Some(p), Outcome::Signal(sig)) => {
// TODO: windows #[cfg(unix)]
if let Some(sig) = sig.to_nix() {
p.signal(sig).await; p.signal(sig).await;
} }
#[cfg(windows)]
if let SubSignal::Terminate = sig {
p.kill().await;
}
// else: https://github.com/watchexec/watchexec/issues/219
}
(Some(p), Outcome::Wait) => { (Some(p), Outcome::Wait) => {
p.wait().await?; p.wait().await?;
} }

View File

@ -1,4 +1,4 @@
use command_group::Signal; use crate::signal::process::SubSignal;
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive] #[non_exhaustive]
@ -16,7 +16,7 @@ pub enum Outcome {
Wait, Wait,
/// Send this signal to the command. /// Send this signal to the command.
Signal(Signal), Signal(SubSignal),
/// Clear the (terminal) screen. /// Clear the (terminal) screen.
Clear, Clear,

View File

@ -1,4 +1,4 @@
//! Signal handling. //! Signal handling.
pub mod source;
pub mod process; pub mod process;
pub mod source;

View File

@ -151,7 +151,9 @@ impl FromStr for SubSignal {
} }
} }
if let Ok(sig) = NixSignal::from_str(&s.to_ascii_uppercase()).or_else(|_| NixSignal::from_str(&format!("SIG{}", s.to_ascii_uppercase()))) { if let Ok(sig) = NixSignal::from_str(&s.to_ascii_uppercase())
.or_else(|_| NixSignal::from_str(&format!("SIG{}", s.to_ascii_uppercase())))
{
return Ok(Self::from_nix(sig)); return Ok(Self::from_nix(sig));
} }