mirror of
https://github.com/zaphar/clio.git
synced 2025-07-22 12:09:48 -04:00
feat: forward sigint to child process
This commit is contained in:
parent
a14ecf4c63
commit
0b0fe7df8e
16
src/main.rs
16
src/main.rs
@ -76,6 +76,7 @@ async fn main() -> anyhow::Result<ExitCode> {
|
||||
let mut rotation_signal_stream = signal(handled_sig)?;
|
||||
let mut sigterm_stream = signal(SignalKind::terminate())?;
|
||||
let mut sigquit_stream = signal(SignalKind::quit())?;
|
||||
let mut sigint_stream = signal(SignalKind::interrupt())?;
|
||||
// Setup our output wiring.
|
||||
let app_name = match args.cmd.first() {
|
||||
Some(n) => n,
|
||||
@ -193,6 +194,21 @@ async fn main() -> anyhow::Result<ExitCode> {
|
||||
}
|
||||
}
|
||||
}
|
||||
_ = sigint_stream.recv() => {
|
||||
// NOTE(zaphar): This is a giant hack.
|
||||
// If https://github.com/tokio-rs/tokio/issues/3379 ever get's implemented it will become
|
||||
// unnecessary.
|
||||
use nix::{
|
||||
sys::signal::{kill, Signal::SIGINT},
|
||||
unistd::Pid,
|
||||
};
|
||||
if let Some(pid) = child.id() {
|
||||
// If the child hasn't already completed, send a SIGTERM.
|
||||
if let Err(e) = kill(Pid::from_raw(pid.try_into().expect("Invalid PID")), SIGINT) {
|
||||
eprintln!("Failed to forward SIGINT to child process: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
result = child.wait() => {
|
||||
// The child has finished
|
||||
return cleanup(result, &args.pid_file).await;
|
||||
|
Loading…
x
Reference in New Issue
Block a user