Use async-signal instead of signal-hook (#42)
This commit is contained in:
parent
d9d97d0299
commit
d45d6f1094
|
@ -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"
|
||||
|
||||
|
|
19
src/lib.rs
19
src/lib.rs
|
@ -203,17 +203,24 @@ impl Child {
|
|||
}
|
||||
|
||||
} else if #[cfg(unix)] {
|
||||
static SIGNALS: OnceCell<Mutex<signal_hook::iterator::Signals>> = OnceCell::new();
|
||||
use async_signal::{Signal, Signals};
|
||||
|
||||
static SIGNALS: OnceCell<Signals> = 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.
|
||||
|
|
Loading…
Reference in New Issue