Use async-signal instead of signal-hook (#42)

This commit is contained in:
John Nunley 2023-06-11 11:21:40 -07:00 committed by GitHub
parent d9d97d0299
commit d45d6f1094
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 11 deletions

View File

@ -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"

View File

@ -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.