From 6145cdcf37112febacd458e56bdd7f5db8c8aef3 Mon Sep 17 00:00:00 2001 From: Roman Iten Date: Thu, 26 Sep 2019 14:51:39 +0200 Subject: [PATCH] run: close connection to spawned processes on kill From the man page of expect: > Both expect and interact will detect when the current process exits > and implicitly do a close. But if you kill the process by, say, "exec > kill $pid", you will need to explicitly call close. Fixes #3569 --- repos/gems/run/depot_autopilot.run | 7 +++---- tool/run/run | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/repos/gems/run/depot_autopilot.run b/repos/gems/run/depot_autopilot.run index a5c9378a5..72247b208 100644 --- a/repos/gems/run/depot_autopilot.run +++ b/repos/gems/run/depot_autopilot.run @@ -112,8 +112,7 @@ proc autopilot_run_genode_until {{wait_for_re forever} {timeout_value 0} {runnin # kill the spawned load process if there is one if {[load_spawn_id] != -1} { - set pid [exp_pid -i [load_spawn_id]] - exec kill -9 $pid + kill_spawned [load_spawn_id] } incr retry -1; @@ -830,7 +829,7 @@ while {1} { if {$run_genode_failed} { # shut-down running system - exec kill -9 [exp_pid -i $serial_id] + kill_spawned $serial_id run_power_off # remember result of last test @@ -902,7 +901,7 @@ while {1} { { # shut-down running system puts "Re-booting to meet maximum number of tests per boot for this platform" - exec kill -9 [exp_pid -i $serial_id] + kill_spawned $serial_id run_power_off # prepare system re-boot diff --git a/tool/run/run b/tool/run/run index b56204953..17693294b 100755 --- a/tool/run/run +++ b/tool/run/run @@ -307,8 +307,7 @@ proc run_genode_until {{wait_for_re forever} {timeout_value 0} {running_spawn_id # kill the spawned load process if there is one if {[load_spawn_id] != -1} { - set pid [exp_pid -i [load_spawn_id]] - exec kill -9 $pid + kill_spawned [load_spawn_id] } incr retry -1; @@ -329,6 +328,17 @@ proc run_genode_until {{wait_for_re forever} {timeout_value 0} {running_spawn_id } +## +# "Safely" kill spawned process +# +proc kill_spawned {spawn_id} { + set pid [exp_pid -i $spawn_id] + close -i $spawn_id + exec kill -9 $pid + wait -i $spawn_id +} + + ## # Remove color information from output #