1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 03:57:44 +00:00

avoid sending twice same signal to child process

This commit is contained in:
Ulrich Hornung 2024-03-12 19:04:15 +01:00
parent 1725479c06
commit abfd000367
No known key found for this signature in database
GPG key ID: 64EA3BAAF1BC0603

View file

@ -202,16 +202,17 @@ fn send_signal(process: &mut Child, signal: usize, foreground: bool) {
// NOTE: GNU timeout doesn't check for errors of signal. // NOTE: GNU timeout doesn't check for errors of signal.
// The subprocess might have exited just after the timeout. // The subprocess might have exited just after the timeout.
// Sending a signal now would return "No such process", but we should still try to kill the children. // Sending a signal now would return "No such process", but we should still try to kill the children.
_ = process.send_signal(signal); match foreground {
if !foreground { true => _ = process.send_signal(signal),
false => {
_ = process.send_signal_group(signal); _ = process.send_signal_group(signal);
let kill_signal = signal_by_name_or_value("KILL").unwrap(); let kill_signal = signal_by_name_or_value("KILL").unwrap();
let continued_signal = signal_by_name_or_value("CONT").unwrap(); let continued_signal = signal_by_name_or_value("CONT").unwrap();
if signal != kill_signal && signal != continued_signal { if signal != kill_signal && signal != continued_signal {
_ = process.send_signal(continued_signal);
_ = process.send_signal_group(continued_signal); _ = process.send_signal_group(continued_signal);
} }
} }
}
} }
/// Wait for a child process and send a kill signal if it does not terminate. /// Wait for a child process and send a kill signal if it does not terminate.