feat: forward sigint to child process

This commit is contained in:
Jeremy Wall 2024-06-06 09:08:18 -04:00
parent a14ecf4c63
commit 0b0fe7df8e

View File

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