@@ -202,14 +202,15 @@ fn send_signal(process: &mut Child, signal: usize, foreground: bool) {
202
202
// NOTE: GNU timeout doesn't check for errors of signal.
203
203
// The subprocess might have exited just after the timeout.
204
204
// Sending a signal now would return "No such process", but we should still try to kill the children.
205
- _ = process. send_signal ( signal) ;
206
- if !foreground {
207
- _ = process. send_signal_group ( signal) ;
208
- let kill_signal = signal_by_name_or_value ( "KILL" ) . unwrap ( ) ;
209
- let continued_signal = signal_by_name_or_value ( "CONT" ) . unwrap ( ) ;
210
- if signal != kill_signal && signal != continued_signal {
211
- _ = process. send_signal ( continued_signal) ;
212
- _ = process. send_signal_group ( continued_signal) ;
205
+ match foreground {
206
+ true => _ = process. send_signal ( signal) ,
207
+ false => {
208
+ _ = process. send_signal_group ( signal) ;
209
+ let kill_signal = signal_by_name_or_value ( "KILL" ) . unwrap ( ) ;
210
+ let continued_signal = signal_by_name_or_value ( "CONT" ) . unwrap ( ) ;
211
+ if signal != kill_signal && signal != continued_signal {
212
+ _ = process. send_signal_group ( continued_signal) ;
213
+ }
213
214
}
214
215
}
215
216
}
@@ -342,8 +343,15 @@ fn timeout(
342
343
send_signal ( process, signal, foreground) ;
343
344
match kill_after {
344
345
None => {
346
+ let status = process. wait ( ) ?;
345
347
if preserve_status {
346
- Err ( ExitStatus :: SignalSent ( signal) . into ( ) )
348
+ if let Some ( ec) = status. code ( ) {
349
+ Err ( ec. into ( ) )
350
+ } else if let Some ( sc) = status. signal ( ) {
351
+ Err ( ExitStatus :: SignalSent ( sc. try_into ( ) . unwrap ( ) ) . into ( ) )
352
+ } else {
353
+ Err ( ExitStatus :: CommandTimedOut . into ( ) )
354
+ }
347
355
} else {
348
356
Err ( ExitStatus :: CommandTimedOut . into ( ) )
349
357
}
0 commit comments