diff options
-rw-r--r-- | lib/remote.exp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/remote.exp b/lib/remote.exp index 83472f7..1c9971a 100644 --- a/lib/remote.exp +++ b/lib/remote.exp @@ -109,11 +109,15 @@ proc close_wait_program { program_id pid {wres_varname ""} } { # Reap it. set res [catch "wait -i $program_id" wres] - if {$exec_pid != -1} { + if { $exec_pid != -1 && [llength $pid] == 1 } { # We reaped the process, so cancel the pending force-kills, as # otherwise if the PID is reused for some other unrelated # process, we'd kill the wrong process. # + # Do this if the PID list only has a single entry however, as + # otherwise `wait' will have returned right away regardless of + # whether any process of the pipeline has exited. + # # Use `catch' in case the force-kills have completed, so as not # to cause TCL to choke if `kill' returns a failure. catch {exec sh -c "kill -9 $exec_pid" >& /dev/null} @@ -242,6 +246,12 @@ proc local_exec { commandline inp outp timeout } { } set r2 [close_wait_program $spawn_id $pid wres] if { $id > 0 } { + if { $pid > 0 } { + # If timed-out, don't wait for all the processes associated + # with the pipeline to terminate as a stuck one would cause + # us to hang. + catch {fconfigure $id -blocking false} + } set r2 [catch "close $id" res] } else { verbose "waitres is $wres" 2 @@ -387,6 +397,12 @@ proc standard_close { host } { close_wait_program $shell_id $pid if {[info exists oid]} { + if { $pid > 0 } { + # Don't wait for all the processes associated with the + # pipeline to terminate as a stuck one would cause us + # to hang. + catch {fconfigure $oid -blocking false} + } catch "close $oid" } |