]> granicus.if.org Git - procps-ng/commitdiff
Reliably kill test processes
authorCraig Small <csmall@enc.com.au>
Tue, 1 Jul 2014 08:51:21 +0000 (18:51 +1000)
committerCraig Small <csmall@enc.com.au>
Tue, 1 Jul 2014 08:51:21 +0000 (18:51 +1000)
It seems command -v also includes built-ins so checking for kill
is useless because it finds the built-in and those machines or
environments that have no /bin/kill fail at the check stage.
Oh and then TCL exec doesn't spawn a shell.

After reading way too many TCL websites, I believe this should
fix the problem. TCL quoting is... different to say the least but
it works reliably here. The script now even picked up a typo elsewhere
which was nice.

This change should stop the intermittent FTBFS bugs from the Debian
pbuilders, I hope! You'd think kill $var wouldn't be this difficult.

testsuite/config/unix.exp
testsuite/pgrep.test/pgrep.exp
testsuite/pkill.test/pkill.exp

index 700c38ee7dd1d42941d17bf22e9aaacf9de0f0d5..522efb15a1c0e1d3332590ada8679022d4d466a8 100644 (file)
@@ -7,6 +7,13 @@ set usage_help "\\s*-h, --help\\s+display this help and exit\\s+"
 set usage_version "\\s*-V, --version\\s+output version information and exit\\s+"
 set usage_man "\\s*For more details see \\S+\\."
 
+proc kill_process pid {
+    set cmdline "kill $pid"
+    if { [catch { exec /bin/sh -c $cmdline } msg]} {
+        warning "Could not kill process: $msg\n"
+    }
+}
+
 proc procps_v_version { tool } {
   global topdir
   set toolpath ${topdir}${tool}
@@ -131,3 +138,11 @@ proc make_testproc { } {
     set testproc1_pid [ exec $testproc_path $sleep_time & ]
     set testproc2_pid [ exec $testproc_path $sleep_time & ]
 }
+
+proc kill_testproc { } {
+    global testproc_path testproc1_pid testproc2_pid
+
+    kill_process $testproc1_pid
+    kill_process $testproc2_pid
+    file delete $testproc_path
+}
index 248c45fb81a357387ecb5eae4a25cac423772759..152b6eccb5456a07741bacbc203988cc22c7b580 100644 (file)
@@ -16,12 +16,6 @@ set test "pgprep with no arguments"
 spawn $pgrep
 expect_pass "$test" "^\(lt-\)\?pgrep: no matching criteria specified\\s*"
 
-# Tests that don't need the test process go above here
-if { [ catch { exec sh -c "command -v kill" } kill_path] } {
-  untested { kill path not found }
-  return
-}
-  
 make_testproc
 
 set testproc_len [ string length $testproc_comm ]
@@ -123,6 +117,4 @@ expect_blank $test
 
 
 # Cleanup
-eval exec "$kill_path $testproc1_pid"
-eval exec "$kill_path $testproc2_pid"
-file delete $testproc_path
+kill_testproc
index 2c9f91e64370cd0d1db9b9488404719a97674fe8..5eece7de8f23691323e23b4e0d6cdf4fe7952784 100644 (file)
@@ -16,12 +16,6 @@ set test "pkill with no arguments"
 spawn $pkill
 expect_pass "$test" "^\(lt-\)\?pkill: no matching criteria specified\\s*"
 
-# Tests that don't need the test process go above here
-if { [ catch { exec sh -c "command -v kill" } kill_path] } {
-  untested { kill path not found }
-  return
-}
-
 make_testproc
 set testproc_len [ string length $testproc_comm ]
 set testproc_trim [ string range $testproc_comm 0 [ expr { $testproc_len - 2 } ] ]
@@ -132,6 +126,4 @@ untested "$test"
 
 
 # Cleanup
-eval exec "$kill_path $testproc1_pid"
-eval exec "$kill_path $testproc2_pid"
-exec rm $testproc_path
+kill_testproc