Compare commits

...

5 Commits

Author SHA1 Message Date
Félix Saparelli c237d3b801
Merge c5a1cca81c into 72f069a847 2024-05-05 16:13:24 -03:00
Félix Saparelli 72f069a847
chore: Release 2024-04-30 20:41:43 +12:00
Adit 4affed6fff
fix(cli): recursive paths provided by user getting treated non-recursively (#828) 2024-04-30 07:10:28 +00:00
Félix Saparelli c5a1cca81c
WIP: listen for SIGSTOP in lib 2023-12-09 23:20:03 +13:00
Félix Saparelli 7ea7d2629d
signals: add first-class SIGSTOP etc 2023-12-09 23:08:18 +13:00
10 changed files with 93 additions and 16 deletions

View File

@ -3,8 +3,8 @@ message: |
If you use this software, please cite it using these metadata.
title: "Watchexec: a tool to react to filesystem changes, and a crate ecosystem to power it"
version: "2.1.0"
date-released: 2024-04-28
version: "2.1.1"
date-released: 2024-04-30
repository-code: https://github.com/watchexec/watchexec
license: Apache-2.0

2
Cargo.lock generated
View File

@ -4032,7 +4032,7 @@ dependencies = [
[[package]]
name = "watchexec-cli"
version = "2.1.0"
version = "2.1.1"
dependencies = [
"ahash",
"argfile",

View File

@ -1,6 +1,6 @@
[package]
name = "watchexec-cli"
version = "2.1.0"
version = "2.1.1"
authors = ["Félix Saparelli <felix@passcod.name>", "Matt Green <mattgreenrocks@gmail.com>"]
license = "Apache-2.0"

View File

@ -1243,7 +1243,7 @@ pub async fn get_args() -> Result<(Args, Option<WorkerGuard>)> {
canonicalize(project_origin.join(path)).into_diagnostic()
}
}
.map(WatchedPath::non_recursive)
.map(WatchedPath::recursive)
})
.chain(take(&mut args.non_recursive_paths).into_iter().map(|path| {
{

View File

@ -3,7 +3,7 @@
<assemblyIdentity
type="win32"
name="Watchexec.Cli.watchexec"
version="2.1.0.0"
version="2.1.1.0"
/>
<trustInfo>

View File

@ -55,13 +55,14 @@ async fn imp_worker(
debug!("launching unix signal worker");
macro_rules! listen {
($sig:ident) => {{
trace!(kind=%stringify!($sig), "listening for unix signal");
signal(SignalKind::$sig()).map_err(|err| CriticalError::IoError {
about: concat!("setting ", stringify!($sig), " signal listener"), err
})?
}}
}
($sig:ident, $signum:expr) => {{
trace!(kind=%stringify!($sig), "listening for unix signal");
signal($signum).map_err(|err| CriticalError::IoError {
about: concat!("setting ", stringify!($sig), " signal listener"), err
})?
}};
($sig:ident) => (listen!($sig, SignalKind::$sig()));
}
let mut s_hangup = listen!(hangup);
let mut s_interrupt = listen!(interrupt);
@ -70,6 +71,30 @@ async fn imp_worker(
let mut s_user1 = listen!(user_defined1);
let mut s_user2 = listen!(user_defined2);
// TODO: option to customise set of signals being listened to, so we can safely listen to sigstop only when requested
let mut s_tstp = if let Some(signum) = Signal::TerminalSuspend.to_nix().map(|s| s as i32) {
listen!(terminal_suspend, SignalKind::from_raw(signum))
} else {
signal(SignalKind::from_raw(9)).map_err(|err| CriticalError::IoError {
about: concat!("setting unreceivable signal listener"), err
})?
};
let mut s_stop = if let Some(signum) = Signal::Suspend.to_nix().map(|s| s as i32) {
listen!(suspend, SignalKind::from_raw(signum))
} else {
signal(SignalKind::from_raw(9)).map_err(|err| CriticalError::IoError {
about: concat!("setting unreceivable signal listener"), err
})?
};
let mut s_cont = if let Some(signum) = Signal::Continue.to_nix().map(|s| s as i32) {
listen!(r#continue, SignalKind::from_raw(signum))
} else {
signal(SignalKind::from_raw(9)).map_err(|err| CriticalError::IoError {
about: concat!("setting unreceivable signal listener"), err
})?
};
loop {
let sig = select!(
_ = s_hangup.recv() => Signal::Hangup,
@ -78,6 +103,9 @@ async fn imp_worker(
_ = s_terminate.recv() => Signal::Terminate,
_ = s_user1.recv() => Signal::User1,
_ = s_user2.recv() => Signal::User2,
_ = s_tstp.recv() => Signal::TerminalSuspend,
_ = s_stop.recv() => Signal::Suspend,
_ = s_cont.recv() => Signal::Continue,
);
debug!(?sig, "received unix signal");

View File

@ -10,6 +10,7 @@
## v2.1.0 (2023-12-09)
- Derive `Hash` for `Signal`.
- Add `Continue`, `Suspend`, and `TerminalSuspend` as first-class signals.
## v2.0.0 (2023-11-29)

View File

@ -85,6 +85,27 @@ pub enum Signal {
/// This signal is generally used to reload configuration.
User2,
/// Sent to a process to unsuspend it.
///
/// On Unix, this is `SIGCONT`. On Windows, it is ignored.
///
/// See also [`Suspend`](Signal::Suspend) and [`TerminalSuspend`][Signal::TerminalSuspend].
Continue,
/// Indicate that the process should suspend itself.
///
/// On Unix, this is `SIGSTOP`. On Windows, it is ignored.
///
/// See also [`TerminalSuspend`][Signal::TerminalSuspend].
Suspend,
/// Indicate that the process should suspend itself (issued from the terminal).
///
/// On Unix, this is `SIGTSTP`. On Windows, it is ignored.
///
/// See also [`Suspend`][Signal::Suspend].
TerminalSuspend,
/// Indicate using a custom signal.
///
/// Internally, this is converted to a [`nix::Signal`](https://docs.rs/nix/*/nix/sys/signal/enum.Signal.html)
@ -137,6 +158,9 @@ impl Signal {
Self::Terminate => Some(NixSignal::SIGTERM),
Self::User1 => Some(NixSignal::SIGUSR1),
Self::User2 => Some(NixSignal::SIGUSR2),
Self::Suspend => Some(NixSignal::SIGSTOP),
Self::TerminalSuspend => Some(NixSignal::SIGTSTP),
Self::Continue => Some(NixSignal::SIGCONT),
Self::Custom(sig) => NixSignal::try_from(sig).ok(),
}
}
@ -154,6 +178,9 @@ impl Signal {
NixSignal::SIGTERM => Self::Terminate,
NixSignal::SIGUSR1 => Self::User1,
NixSignal::SIGUSR2 => Self::User2,
NixSignal::SIGSTOP => Self::Suspend,
NixSignal::SIGTSTP => Self::TerminalSuspend,
NixSignal::SIGCONT => Self::Continue,
sig => Self::Custom(sig as _),
}
}
@ -172,6 +199,9 @@ impl From<i32> for Signal {
10 => Self::User1,
12 => Self::User2,
15 => Self::Terminate,
18 => Self::Continue,
19 => Self::Suspend,
20 => Self::TerminalSuspend,
_ => Self::Custom(raw),
}
}
@ -228,6 +258,9 @@ impl Signal {
"TERM" | "SIGTERM" | "15" => Ok(Self::Terminate),
"USR1" | "SIGUSR1" | "10" => Ok(Self::User1),
"USR2" | "SIGUSR2" | "12" => Ok(Self::User2),
"CONT" | "SIGCONT" | "18" => Ok(Self::Continue),
"STOP" | "SIGSTOP" | "19" => Ok(Self::Suspend),
"TSTP" | "SIGTSTP" | "20" => Ok(Self::TerminalSuspend),
number => match i32::from_str(number) {
Ok(int) => Ok(Self::Custom(int)),
Err(_) => Err(SignalParseError::new(s, "unsupported signal")),
@ -323,6 +356,9 @@ impl fmt::Display for Signal {
(Self::Terminate, true) => "CTRL-BREAK",
(Self::User1, _) => "SIGUSR1",
(Self::User2, _) => "SIGUSR2",
(Self::Continue, _) => "SIGCONT",
(Self::Suspend, _) => "SIGSTOP",
(Self::TerminalSuspend, _) => "SIGTSTP",
(Self::Custom(n), _) => {
return write!(f, "{n}");
}
@ -359,6 +395,12 @@ mod serde_support {
User1,
#[serde(rename = "SIGUSR2")]
User2,
#[serde(rename = "SIGCONT")]
Continue,
#[serde(rename = "SIGSTOP")]
Suspend,
#[serde(rename = "SIGTSTP")]
TerminalSuspend,
}
impl From<Signal> for SerdeSignal {
@ -371,6 +413,9 @@ mod serde_support {
Signal::User1 => Self::Named(NamedSignal::User1),
Signal::User2 => Self::Named(NamedSignal::User2),
Signal::ForceStop => Self::Named(NamedSignal::ForceStop),
Signal::Continue => Self::Named(NamedSignal::Continue),
Signal::Suspend => Self::Named(NamedSignal::Suspend),
Signal::TerminalSuspend => Self::Named(NamedSignal::TerminalSuspend),
Signal::Custom(number) => Self::Number(number),
}
}
@ -386,6 +431,9 @@ mod serde_support {
SerdeSignal::Named(NamedSignal::Terminate) => Self::Terminate,
SerdeSignal::Named(NamedSignal::User1) => Self::User1,
SerdeSignal::Named(NamedSignal::User2) => Self::User2,
SerdeSignal::Named(NamedSignal::Continue) => Self::Continue,
SerdeSignal::Named(NamedSignal::Suspend) => Self::Suspend,
SerdeSignal::Named(NamedSignal::TerminalSuspend) => Self::TerminalSuspend,
SerdeSignal::Number(number) => Self::Custom(number),
}
}

View File

@ -1,6 +1,6 @@
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.TH watchexec 1 "watchexec 2.1.0"
.TH watchexec 1 "watchexec 2.1.1"
.SH NAME
watchexec \- Execute commands when watched files change
.SH SYNOPSIS
@ -582,6 +582,6 @@ Use @argfile as first argument to load arguments from the file \*(Aqargfile\*(Aq
Didn\*(Aqt expect this much output? Use the short \*(Aq\-h\*(Aq flag to get short help.
.SH VERSION
v2.1.0
v2.1.1
.SH AUTHORS
Félix Saparelli <felix@passcod.name>, Matt Green <mattgreenrocks@gmail.com>

View File

@ -861,7 +861,7 @@ Didnt expect this much output? Use the short -h flag to get short help.
# VERSION
v2.1.0
v2.1.1
# AUTHORS