From d45d6f1094b9da7b3a9c26590fb24604615662a3 Mon Sep 17 00:00:00 2001 From: John Nunley Date: Sun, 11 Jun 2023 11:21:40 -0700 Subject: [PATCH] Use async-signal instead of signal-hook (#42) --- Cargo.toml | 6 +----- src/lib.rs | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1da6bf1..c42a1db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,13 +22,9 @@ futures-lite = "1.11.0" [target.'cfg(unix)'.dependencies] async-io = "1.8" +async-signal = "0.2.0" rustix = { version = "0.37", default-features = false, features = ["std", "fs"] } -[target.'cfg(unix)'.dependencies.signal-hook] -version = "0.3.0" -features = ["iterator"] -default-features = false - [target.'cfg(windows)'.dependencies] blocking = "1.0.0" diff --git a/src/lib.rs b/src/lib.rs index 6a6d318..151c35c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -203,17 +203,24 @@ impl Child { } } else if #[cfg(unix)] { - static SIGNALS: OnceCell> = OnceCell::new(); + use async_signal::{Signal, Signals}; + + static SIGNALS: OnceCell = OnceCell::new(); // Make sure the signal handler is registered before interacting with the process. - SIGNALS.get_or_init_blocking(|| Mutex::new( - signal_hook::iterator::Signals::new([signal_hook::consts::SIGCHLD]) - .expect("cannot set signal handler for SIGCHLD"), - )); + SIGNALS.get_or_init_blocking(|| { + Signals::new(Some(Signal::Child)) + .expect("Failed to register SIGCHLD handler") + }); // Waits for the next SIGCHLD signal. fn wait_sigchld() { - SIGNALS.get().expect("Signals not registered").lock().unwrap().forever().next(); + async_io::block_on( + SIGNALS + .get() + .expect("Signals not registered") + .next() + ); } // Wraps a sync I/O type into an async I/O type.