]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: cleanup background processes upon interruption
authorPádraig Brady <P@draigBrady.com>
Fri, 1 May 2015 04:26:38 +0000 (05:26 +0100)
committerPádraig Brady <P@draigBrady.com>
Mon, 11 May 2015 22:02:16 +0000 (23:02 +0100)
Reap background processes so that:
- Stray processes aren't left on the system
- Files aren't held open causing deletion issues on NFS
- Partitions used to run the tests from can be unmounted

* tests/tail-2/F-vs-missing.sh: Add the `kill && wait` of the
background $pid(s) to cleanup_().
* tests/tail-2/F-vs-rename.sh: Likewise.
* tests/tail-2/f-vs-rename.sh: Likewise.
* tests/tail-2/append-only.sh: Likewise.
* tests/tail-2/assert-2.sh: Likewise.
* tests/tail-2/assert.sh: Likewise.
* tests/tail-2/flush-initial.sh: Likewise.
* tests/tail-2/inotify-hash-abuse.sh: Likewise.
* tests/tail-2/inotify-hash-abuse2.sh: Likewise.
* tests/tail-2/inotify-race.sh: Likewise.
* tests/tail-2/inotify-rotate-resources.sh: Likewise.
* tests/tail-2/inotify-rotate.sh: Likewise.
* tests/tail-2/pid.sh: Likewise.
* tests/tail-2/pipe-f2.sh: Likewise.
* tests/tail-2/retry.sh: Likewise.
* tests/tail-2/symlink.sh: Likewise.
* tests/tail-2/tail-n0f.sh: Likewise.
* tests/tail-2/wait.sh: Likewise.
* tests/cp/existing-perm-race.sh: Likewise.
* tests/cp/file-perm-race.sh: Likewise.
* tests/cp/parent-perm-race.sh: Likewise.
* tests/cp/sparse-to-pipe.sh: Likewise.
* tests/dd/stats.sh: Likewise.
* tests/du/move-dir-while-traversing.sh: Likewise.
* tests/misc/cat-buf.sh: Likewise.
* tests/misc/help-version.sh: Likewise.
* tests/misc/printf-surprise.sh: Likewise.
* tests/misc/sort-compress-proc.sh: Likewise.
* tests/misc/sort-spinlock-abuse.sh: Likewise.
* tests/misc/stdbuf.sh: Likewise.
* tests/misc/tac-continue.sh: Likewise.
* tests/misc/timeout-group.sh: Likewise.
* tests/mv/i-3.sh: Likewise.
* tests/rm/dangling-symlink.sh: Likewise.
* tests/rm/isatty.sh: Likewise.
* cfg.mk (sc_prohibit_test_background_without_cleanup_):
A new syntax-check to ensure cleanup_() is defined
when background tasks are created in a test.

36 files changed:
cfg.mk
tests/cp/existing-perm-race.sh
tests/cp/file-perm-race.sh
tests/cp/parent-perm-race.sh
tests/cp/sparse-to-pipe.sh
tests/dd/stats.sh
tests/du/move-dir-while-traversing.sh
tests/misc/cat-buf.sh
tests/misc/help-version.sh
tests/misc/printf-surprise.sh
tests/misc/sort-compress-proc.sh
tests/misc/sort-spinlock-abuse.sh
tests/misc/stdbuf.sh
tests/misc/tac-continue.sh
tests/misc/timeout-group.sh
tests/mv/i-3.sh
tests/rm/dangling-symlink.sh
tests/rm/isatty.sh
tests/tail-2/F-vs-missing.sh
tests/tail-2/F-vs-rename.sh
tests/tail-2/append-only.sh
tests/tail-2/assert-2.sh
tests/tail-2/assert.sh
tests/tail-2/f-vs-rename.sh
tests/tail-2/flush-initial.sh
tests/tail-2/inotify-hash-abuse.sh
tests/tail-2/inotify-hash-abuse2.sh
tests/tail-2/inotify-race.sh
tests/tail-2/inotify-rotate-resources.sh
tests/tail-2/inotify-rotate.sh
tests/tail-2/pid.sh
tests/tail-2/pipe-f2.sh
tests/tail-2/retry.sh
tests/tail-2/symlink.sh
tests/tail-2/tail-n0f.sh
tests/tail-2/wait.sh

diff --git a/cfg.mk b/cfg.mk
index 4f222f630271b4b47e49ff2fd1d3028fbcc16af9..852685353a0181ba883151d3b25c765c7c04e900 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -487,6 +487,13 @@ sc_prohibit_test_ulimit_without_require_:
          | sort | uniq -u | grep . && { echo "$(ME): the above test(s)"\
          " should match require_ulimit_v_ with ulimit -v" 1>&2; exit 1; } || :
 
+# Ensure that tests call the cleanup_ function if using background processes
+sc_prohibit_test_background_without_cleanup_:
+       @(git grep -El '( &$$|&[^&]*=\$$!)' tests;                      \
+         git grep -l 'cleanup_()' tests | sed p)                       \
+         | sort | uniq -u | grep . && { echo "$(ME): the above test(s)"\
+         " should use cleanup_ for background processes" 1>&2; exit 1; } || :
+
 # Ensure that tests call the print_ver_ function for programs which are
 # actually used in that test.
 sc_prohibit_test_calls_print_ver_with_irrelevant_argument:
index 30cbc6ab6a207dfcd5b7efa37f824da7143a406a..f48369cd50d5deabbbde5a65989981f3c6a3e529 100755 (executable)
@@ -37,10 +37,12 @@ chgrp $g1 fifo &&
 chgrp $g2 fifo-copy &&
 chmod g+r fifo-copy || framework-failure
 
+# Terminate any background cp process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 # Copy a fifo's contents.  That way, we can examine the
 # destination permissions before they're finalized.
-cp -p --copy-contents fifo fifo-copy &
-cp_pid=$!
+cp -p --copy-contents fifo fifo-copy & pid=$!
 
 (
   # Now 'cp' is reading the fifo.  Wait for the destination file to
@@ -77,7 +79,7 @@ case $mode in
   *) fail=1;;
 esac
 
-wait $cp_pid || fail=1
+wait $pid || fail=1
 
 # Check that the final mode and group are right.
 ls -l -n fifo-copy >ls.out &&
index 5057dae7bc79842512e5b350f217ec9b5d2c426a..8197962da59984c31fd40bfaed87e77bf6fe16cd 100755 (executable)
@@ -25,10 +25,12 @@ require_local_dir_
 umask 022
 mkfifo_or_skip_ fifo
 
+# Terminate any background cp process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 # Copy a fifo's contents.  That way, we can examine the
 # destination permissions before they're finalized.
-cp -p --copy-contents fifo fifo-copy &
-cp_pid=$!
+cp -p --copy-contents fifo fifo-copy & pid=$!
 
 (
   # Now 'cp' is reading the fifo.  Wait for the destination file to
@@ -51,6 +53,6 @@ case $(cat ls.out) in
 *) fail=1;;
 esac
 
-wait $cp_pid || fail=1
+wait $pid || fail=1
 
 Exit $fail
index 7b254b73f1ab928b20a7c3e9f8e9977fefccf594..c370f9e0646aa819bfca06e61ddbec9bd88c5ac5 100755 (executable)
@@ -26,6 +26,8 @@ umask 002
 mkdir mode ownership d || framework_failure_
 chmod g+s d 2>/dev/null # The cp test is valid either way.
 
+# Terminate any background cp process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
 
 for attr in mode ownership
 do
@@ -33,8 +35,7 @@ do
 
   # Copy a fifo's contents.  That way, we can examine d/$attr's
   # state while cp is running.
-  cp --preserve=$attr -R --copy-contents --parents $attr d &
-  cp_pid=$!
+  cp --preserve=$attr -R --copy-contents --parents $attr d & pid=$!
 
   (
     # Now 'cp' is reading the fifo.
@@ -58,7 +59,7 @@ do
     fail=1;;
   esac
 
-  wait $cp_pid || fail=1
+  wait $pid || fail=1
 done
 
 Exit $fail
index 8fc9e09d6a7d37a1d5cf7c9f3fa1260d1a5aada9..2c3dcefba2d7d66b6153f467054778a6797ac66d 100755 (executable)
@@ -21,14 +21,17 @@ print_ver_ cp
 
 require_sparse_support_
 
+# Terminate any background cp process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 mkfifo_or_skip_ pipe
-timeout 10 cat pipe > copy &
+timeout 10 cat pipe > copy & pid=$!
 
 truncate -s1M sparse || framework_failure_
 cp sparse pipe || fail=1
 
 # Ensure that the cat has completed before comparing.
-wait
+wait $pid
 
 cmp sparse copy || fail=1
 
index 2d3c3a8f1a42ae57010175db0fdf22c2f27a8bc7..e906c7486d0cc94bace1a750f68e5d92251b1f4a 100755 (executable)
@@ -28,6 +28,14 @@ trap '' $SIGINFO
 
 mkfifo_or_skip_ fifo
 
+# Terminate any background processes
+cleanup_()
+{
+  kill $pid  2>/dev/null
+  kill $pid2 2>/dev/null
+  wait
+}
+
 for open in '' '1'; do
   # Run dd with the fullblock iflag to avoid short reads
   # which can be triggered by reception of signals
@@ -39,7 +47,7 @@ for open in '' '1'; do
 
   # dd will block on open until fifo is opened for reading.
   # Timeout in case dd goes away erroneously which we check for below.
-  timeout 10 sh -c 'wc -c < fifo > nwritten' &
+  timeout 10 sh -c 'wc -c < fifo > nwritten' & pid2=$!
 
   # Send lots of signals immediately to ensure dd not killed due
   # to race setting handler, or blocking on open of fifo.
index 7d1b58ab37d9d1f6c89b455ba42dd36fa13b3a78..67bb34580742f67bacdb2acbf965f963b41aea59 100755 (executable)
@@ -71,10 +71,13 @@ for i in $(seq 50); do
   mkdir -p $t/3/a/b/c/$i/$long || framework_failure_
 done
 
+# Terminate any background cp process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 # Prohibit suspension, which could otherwise cause a timeout-induced FP failure.
 trap '' TSTP
 
-timeout 6 ./inotify-watch-for-dir-access.py $t/3/a/b > start-msg &
+timeout 6 ./inotify-watch-for-dir-access.py $t/3/a/b > start-msg & pid=$!
 
 # Wait for the watcher to start...
 nonempty() { test -s start-msg || { sleep $1; return 1; }; }
index 68be86e1ab2b9571a63d7ad2a77954f4d9456ba2..31382481af7933a869ea29fffe390d7d08929ade 100755 (executable)
@@ -26,6 +26,8 @@ print_ver_ cat
 # write separately.
 mkfifo_or_skip_ fifo
 
+# Terminate any background cp process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
 
 echo 1 > exp
 
@@ -33,9 +35,9 @@ cat_buf_1()
 {
   local delay="$1"
 
-  dd count=1 if=fifo > out &
+  dd count=1 if=fifo > out & pid=$!
   (echo 1; sleep $delay; echo 2) | cat -v > fifo
-  wait # for dd to complete
+  wait $pid
   compare exp out
 }
 
index 64d6e1642d4610a727c72a3b015f0aa2154c1d01..e0dd721f944300477052822582a6b9c27176f9cd 100755 (executable)
@@ -25,6 +25,9 @@ export SHELL
 
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 
+# Terminate any background processes
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 expected_failure_status_chroot=125
 expected_failure_status_env=125
 expected_failure_status_nice=125
@@ -216,8 +219,8 @@ id_setup () { args=-u; }
 
 # Use env to avoid invoking built-in sleep of Solaris 11's /bin/sh.
 kill_setup () {
-  env sleep 31.5 &
-  args=$!
+  env sleep 10m & pid=$!
+  args=$pid
 }
 
 link_setup () { args="$tmp_in link-target"; }
index 0af64482dbb6777c7da3bc971e730472d6821fed..20e6b0988ceaa345f00ec36df30236de2ad6e406 100755 (executable)
@@ -53,7 +53,10 @@ mkfifo_or_skip_ fifo
 # http://bugs.debian.org/481543#77
 export MALLOC_PERTURB_=0
 
-head -c 10 fifo > out &
+# Terminate any background process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
+head -c 10 fifo > out & pid=$!
 
 # Choosing the virtual memory limit, 11000 is enough, but 10000 is too
 # little and provokes a "memory exhausted" diagnostic on FreeBSD 9.0-p3.
index a191a3c511954694f80d4ad17cc4a92460fde4a5..4ad42d51487fa0acc3a961ecc657b9bebfa014e1 100755 (executable)
@@ -20,6 +20,9 @@
 print_ver_ sort
 expensive_
 
+# Terminate any background processes
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 SORT_FAILURE=2
 
 seq -w 2000 > exp || fail=1
@@ -63,7 +66,7 @@ done
 # Ignore a random child process created before 'sort' was exec'ed.
 # This bug was also present in coreutils 8.7.
 #
-( (sleep 1; exec false) &
+( (sleep 1; exec false) & pid=$!
   PRE_COMPRESS='test -f ok || sleep 2'
   POST_COMPRESS='touch ok'
   exec sort --compress-program=./compress -S 1k in >out
index 31c5aa200ec4fdf33856855597aea9e5a5a59956..e81abf8012d540c9a0ca97faa6ce47720d7612fd 100755 (executable)
@@ -29,13 +29,16 @@ very_expensive_
 grep '^#define HAVE_PTHREAD_T 1' "$CONFIG_HEADER" > /dev/null ||
   skip_ 'requires pthreads'
 
+# Terminate any background processes
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 seq 100000 > in || framework_failure_
 mkfifo_or_skip_ fifo
 
 # Arrange for sort to require 8.0+ seconds of wall-clock time,
 # while actually using far less than 1 second of CPU time.
 (for i in $(seq 80); do read line; echo $i; sleep .1; done
-  cat > /dev/null) < fifo &
+  cat > /dev/null) < fifo & pid=$!
 
 # However, under heavy load, it can easily take more than
 # one second of CPU time, so set a permissive limit:
index bb1d40ca51e8cab2f6bb7e7792dbb1c3e29826e1..428d4a2f1ee04edf59831141087ce3185cc91d14 100755 (executable)
@@ -58,15 +58,18 @@ test $? = 126 || fail=1
 stdbuf -o1 no_such # no such command
 test $? = 127 || fail=1
 
+# Terminate any background processes
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 # Ensure line buffering stdout takes effect
 stdbuf_linebuffer()
 {
   local delay="$1"
 
   printf '1\n' > exp
-  dd count=1 if=fifo > out 2> err &
+  dd count=1 if=fifo > out 2> err & pid=$!
   (printf '1\n'; sleep $delay; printf '2\n') | stdbuf -oL uniq > fifo
-  wait # for dd to complete
+  wait $pid
   compare exp out
 }
 
@@ -78,9 +81,9 @@ stdbuf_unbuffer()
 
   # Ensure un buffering stdout takes effect
   printf '1\n' > exp
-  dd count=1 if=fifo > out 2> err &
+  dd count=1 if=fifo > out 2> err & pid=$!
   (printf '1\n'; sleep $delay; printf '2\n') | stdbuf -o0 uniq > fifo
-  wait # for dd to complete
+  wait $pid
   compare exp out
 }
 
index 9078cd58ddd0356d79fce56f814012aeb963b4bc..1389072b400becbbcd75f3effb1e0f77a1597e37 100755 (executable)
@@ -33,7 +33,13 @@ if ! test -d "$FULL_PARTITION_TMPDIR"; then
 fi
 
 fp_tmp="$FULL_PARTITION_TMPDIR/tac-cont-$$"
-cleanup_() { rm -f "$fp_tmp"; }
+cleanup_()
+{
+  # Terminate any background process
+  # and remove tmp dir
+  rm -f "$fp_tmp"
+  kill $pid 2>/dev/null && wait $pid
+}
 
 # Make sure we can create an empty file there (i.e., no shortage of inodes).
 if ! touch $fp_tmp; then
@@ -54,7 +60,7 @@ seq 5 > in
 # Give tac a fifo command line argument.
 # This makes it try to create a temporary file in $TMPDIR.
 mkfifo_or_skip_ fifo
-seq 1000 > fifo &
+seq 1000 > fifo & pid=$!
 TMPDIR=$FULL_PARTITION_TMPDIR tac fifo in >out 2>err && fail=1
 
 cat <<\EOF > exp || fail=1
index 77682920bb3bef42f26570034b12ef0018c0141c..054c5aec66f237c09b2b04f82f22de1b76a1f8d0 100755 (executable)
@@ -57,15 +57,17 @@ check_timeout_cmd_running()
     { sleep $delay; return 1; }
 }
 
+# Terminate any background processes
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
 
 # Start above script in its own group.
 # We could use timeout for this, but that assumes an implementation.
-setsid ./group.sh &
+setsid ./group.sh & pid=$!
 # Wait 6.3s for timeout.cmd to start
 retry_delay_ check_timeout_cmd_running .1 6 || fail=1
 # Simulate a Ctrl-C to the group to test timely exit
 # Note dash doesn't support signalling groups (a leading -)
-env kill -INT -- -$!
+env kill -INT -- -$pid
 wait
 test -e int.received || fail=1
 
@@ -82,8 +84,7 @@ start=$(date +%s)
 # Note the first timeout must send a signal that
 # the second is handling for it to be propagated to the command.
 # SIGINT, SIGTERM, SIGALRM etc. are implicit.
-timeout -sALRM 30 timeout -sINT 25 ./timeout.cmd 20&
-pid=$!
+timeout -sALRM 30 timeout -sINT 25 ./timeout.cmd 20 & pid=$!
 # Wait 6.3s for timeout.cmd to start
 retry_delay_ check_timeout_cmd_running .1 6 || fail=1
 kill -ALRM $pid # trigger the alarm of the first timeout command
index 8cee6bd9656c8694271faa114d94d0e7c49ab61a..77d4a44f99f9a17b063bd22dee7b3aa4beb2eca9 100755 (executable)
@@ -39,6 +39,9 @@ tty=$(readlink -f /dev/stdin)
 test -r "$tty" 2>&1 \
   || skip_ '/dev/stdin is not readable'
 
+# Terminate any background processes
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 mv f g < $tty > out 2>&1 & pid=$!
 
 # Test for the expected prompt; sleep upon non-match.
@@ -54,7 +57,7 @@ check_overwrite_prompt()
 # Wait for up to 12.7 seconds for the expected prompt.
 retry_delay_ check_overwrite_prompt .1 7 || { fail=1; cat out; }
 
-kill $pid
+cleanup_
 
 mv -f h i > out 2>&1 || fail=1
 test -f i || fail=1
index 5fb50ecd1bbec3dc84ea67d6ca4081eb3ceb190c..d2e08a8acb7d6afb8b4ff1c4afe600b97ee93f17 100755 (executable)
@@ -25,9 +25,10 @@ print_ver_ rm
 ln -s no-file dangle
 ln -s / symlink
 
+# Terminate any background processes
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
 
-rm ---presume-input-tty dangle symlink &
-pid=$!
+rm ---presume-input-tty dangle symlink & pid=$!
 # The buggy rm (fileutils-4.1.9) would hang here, waiting for input.
 
 # Wait up to 3.1s for rm to remove the files
@@ -40,6 +41,6 @@ check_files_removed() {
 }
 retry_delay_ check_files_removed .1 5 || fail=1
 
-kill $pid > /dev/null 2>&1
+cleanup_
 
 Exit $fail
index 61148d52db152187d6201aae860ce59008f7750f..4eea4432c9461ab42ab561a052fcc37db71053e5 100755 (executable)
@@ -25,10 +25,12 @@ skip_if_root_
 ls /dev/stdin >/dev/null 2>&1 \
   || skip_ 'there is no /dev/stdin file'
 
+# Terminate any background processes
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 touch f
 chmod 0 f
-rm ---presume-input-tty f > out 2>&1 &
-pid=$!
+rm ---presume-input-tty f > out 2>&1 & pid=$!
 
 # Wait a second, to give a buggy rm (as in fileutils-4.0.40)
 # enough time to remove the file.
@@ -37,7 +39,7 @@ sleep 1
 # The file must still exist.
 test -f f || fail=1
 
-kill $pid > /dev/null 2>&1
+cleanup_
 
 # Note the trailing 'x' -- so I don't have to have a trailing
 # blank in this file :-)
index 6622f7e428ec06ab8e8834b7a87c8ea3229cd235..be20ee3b88474194caef4b54864c266e8402f65e 100755 (executable)
@@ -28,6 +28,9 @@ check_tail_output()
     { sleep $delay; return 1; }
 }
 
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
 
@@ -49,9 +52,7 @@ for mode in '' '---disable-inotify'; do
   tail_re='has appeared' retry_delay_ check_tail_output .1 7 ||
     { echo "$0: file: unexpected delay?"; cat out; fail=1; }
 
-  kill $pid
-
-  wait $pid
+  cleanup_
 done
 
 
index e087ec2e8ca19c7d053f10ac50a7dc531da0f8ad..ee61a548b602f584d93ece85f81ce709bdc30c4f 100755 (executable)
@@ -28,6 +28,9 @@ check_tail_output()
     { sleep $delay; return 1; }
 }
 
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
 
@@ -74,9 +77,7 @@ for mode in '' '---disable-inotify'; do
   retry_delay_ tail_f_vs_rename_3 .1 7 ||
     { echo "$0: a: unexpected delay?"; cat out; fail=1; }
 
-  kill $pid
-
-  wait $pid
+  cleanup_
 done
 
 Exit $fail
index 9da10ae9c2d0573743e17ed1c2aab8dab77f4bcb..2ea5df1fe908ec052a756512cf184142c708b87b 100755 (executable)
@@ -21,6 +21,9 @@
 print_ver_ tail
 require_root_
 
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 chattr_a_works=1
 touch f
 chattr +a f 2>/dev/null || chattr_a_works=0
@@ -35,6 +38,7 @@ fi
 for mode in '' '---disable-inotify'; do
   sleep 1 & pid=$!
   tail --pid=$pid -f $mode f || fail=1
+  cleanup_
 done
 
 chattr -a f 2>/dev/null
index aaf8785ae871b889b8154b549835698e74fbd095..67804feaf8fb44790fef27721c0abbce60e4e7a8 100755 (executable)
@@ -28,10 +28,12 @@ check_tail_output()
     { sleep $delay; return 1; }
 }
 
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
 
-
 for mode in '' '---disable-inotify'; do
   rm -f a foo out
   touch a || framework_failure_
@@ -41,16 +43,15 @@ for mode in '' '---disable-inotify'; do
   # Wait up to 12.7s for tail to start.
   echo x > a || framework_failure_
   tail_re='^x$' retry_delay_ check_tail_output .1 7 ||
-    { cat out; fail=1; }
+    { cat out; fail=1; break; }
 
   # Wait up to 12.7s for tail to notice new foo file
   ok='ok ok ok'
   echo "$ok" > foo || framework_failure_
   tail_re="^$ok$" retry_delay_ check_tail_output .1 7 ||
-    { echo "$0: foo: unexpected delay?"; cat out; fail=1; }
+    { echo "$0: foo: unexpected delay?"; cat out; fail=1; break; }
 
-  kill $pid
-  wait $pid
+  cleanup_
 done
 
 Exit $fail
index 906e364b5d56ecb415063bbe943ce672feb136e2..43bd1e1461f0d66b80a1dfe320accd3d381e1bb2 100755 (executable)
@@ -33,10 +33,12 @@ check_tail_output()
     { sleep $delay; return 1; }
 }
 
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
 
-
 for mode in '' '---disable-inotify'; do
   rm -f a foo out
   touch a foo || framework_failure_
@@ -46,22 +48,21 @@ for mode in '' '---disable-inotify'; do
   # Wait up to 12.7s for tail to start.
   echo x > a || framework_failure_
   tail_re='^x$' retry_delay_ check_tail_output .1 7 ||
-    { cat out; fail=1; }
+    { cat out; fail=1; break; }
 
   # Wait 12.7s for this diagnostic:
   # tail: foo: No such file or directory
   rm foo || framework_failure_
   tail_re='No such file' retry_delay_ check_tail_output .1 7 ||
-    { cat out; fail=1; }
+    { cat out; fail=1; break; }
 
   # Wait up to 12.7s for tail to notice new foo file
   ok='ok ok ok'
   echo "$ok" > foo || framework_failure_
   tail_re="^$ok$" retry_delay_ check_tail_output .1 7 ||
-    { echo "$0: foo: unexpected delay?"; cat out; fail=1; }
+    { echo "$0: foo: unexpected delay?"; cat out; fail=1; break; }
 
-  kill $pid
-  wait $pid
+  cleanup_
 done
 
 Exit $fail
index bfd0949b47de764422f3164da48f81b81e131c61..083d71449782a95bbb13117bebc5b6c1324620e2 100755 (executable)
@@ -28,6 +28,9 @@ check_tail_output()
     { sleep $delay; return 1; }
 }
 
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
 
@@ -47,9 +50,7 @@ for mode in '' '---disable-inotify'; do
   # Wait up to 12.7s for "y" to appear in the output:
   tail_re='^y$' retry_delay_ check_tail_output .1 7 || { cat out; fail=1; }
 
-  kill $pid
-
-  wait $pid
+  cleanup_
 done
 
 Exit $fail
index aaeb878f5585aa18603946be197d774fc4191897..a25bbeb1b8facc8b84d1dbf629af5dd2c13b7d8c 100755 (executable)
@@ -22,10 +22,13 @@ print_ver_ tail
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
 
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 echo line > in || framework_failure_
 # Output should be buffered since we're writing to file
 # so we're depending on the flush to write out
-tail $fastpoll -f in > out & tail_pid=$!
+tail $fastpoll -f in > out & pid=$!
 
 # Wait for 3.1s for the file to be flushed.
 tail_flush()
@@ -37,8 +40,6 @@ tail_flush()
 }
 retry_delay_ tail_flush .1 5 || fail=1
 
-kill $tail_pid
-
-wait $tail_pid
+cleanup_
 
 Exit $fail
index d8c14c1c5eb29897d38dab4f8972e396aaec8734..6333699c12ebb1bcc3aa860d842713faee753513 100755 (executable)
@@ -30,6 +30,9 @@ check_tail_output()
     { sleep $delay; return 1; }
 }
 
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
 
@@ -58,10 +61,10 @@ for mode in '' '---disable-inotify'; do
   tail_re='has appeared' retry_delay_ check_tail_output .1 6 ||
     { cat out; fail=1; }
 
-  # Kill the working tail, or fail if it has already aborted
-  kill $pid || fail=1
+  # Double check that tail hasn't aborted
+  kill -0 $pid || fail=1
 
-  wait $pid
+  cleanup_
 done
 
 
index b054237951ebeab55ab2992f5c279c3a7d789ae1..d641c241bfdc25ba226fdd7b02a038563ec20355 100755 (executable)
@@ -20,6 +20,9 @@
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ tail
 
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
 
@@ -34,10 +37,10 @@ for mode in '' '---disable-inotify'; do
     touch f
   done
 
-  # Kill the working tail, or fail if it has already aborted
-  kill $pid || fail=1
+  # Ensure tail hasn't aborted
+  kill -0 $pid || fail=1
 
-  wait $pid
+  cleanup_
 done
 
 Exit $fail
index d28f898b60c7826d8c11d251e917e62ae179903a..6e1a7fa4089c75716db40fad22ec4d7db20746a5 100755 (executable)
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ tail
 
+# Terminate any background gdb/tail process
+cleanup_() {
+  kill $pid 2>/dev/null && wait $pid
+  kill $sleep 2>/dev/null && wait $sleep
+}
+
 touch file || framework_failure_
 touch tail.out || framework_failure_
 
@@ -75,8 +81,7 @@ gdb -nx --batch-silent \
     --eval-command='shell echo never-seen-with-tail-7.5 >> file' \
     --eval-command='continue'                      \
     --eval-command='quit'                          \
-    tail < /dev/null > /dev/null 2>&1 &
-pid=$!
+    tail < /dev/null > /dev/null 2>&1 & pid=$!
 
 tail --pid=$pid -f tail.out | (read; kill $pid)
 
index b65ceb7c5b356c5c30b522bccf37d5f5a075aa92..7922365168ac821a6b2c190abd66d68cda5c0ca7 100755 (executable)
@@ -48,13 +48,17 @@ cleanup_fail()
   fail=1
 }
 
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 fastpoll='-s.1 --max-unchanged-stats=1'
 
-# Normally less than a second is required here, but with heavy load
-# and a lot of disk activity, even 20 seconds per grep_timeout is insufficient,
-# which leads to this timeout (used as a safety net for cleanup)
-# killing tail before processing is completed.
 touch k || framework_failure_
+
+# Note the timeout guard isn't strictly necessary here,
+# however without it strace will ignore SIGTERM.
+# strace does always honor SIGTERM with the -I2 option,
+# though that's not available on RHEL6 for example.
 timeout 180 strace -e inotify_rm_watch -o strace.out \
   tail -F $fastpoll k >> out 2>&1 & pid=$!
 
@@ -92,7 +96,7 @@ for i in $(seq 2); do
 done
 
 test "$reverted_to_polling_" = 1 && skip_ 'inotify resources already depleted'
-kill $pid
-wait $pid
+
+cleanup_
 
 Exit $fail
index be1f07e5bbced6a74a0bd1e42a06acacae95f50f..638a3bbb6bf00922e375c2f33a41144c85dfcde0 100755 (executable)
@@ -32,11 +32,14 @@ check_tail_output()
 # Wait up to 25.5 seconds for grep REGEXP 'out' to succeed.
 grep_timeout() { tail_re="$1" retry_delay_ check_tail_output .1 8; }
 
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 cleanup_fail()
 {
   cat out
   warn_ $1
-  kill $pid
+  cleanup_
   fail=1
 }
 
@@ -68,8 +71,7 @@ for i in $(seq 50); do
     # wait for "ok" to appear in 'out'
     grep_timeout 'ok' || { cleanup_fail 'failed to detect echoed ok'; break; }
 
-    kill $pid
+    cleanup_
 done
 
-wait
 Exit $fail
index 7a4986763b4b8655d4ff285e3b0464d5ee8a3d05..b410478e588b21682457596023f439c7f2ada3bc 100755 (executable)
@@ -22,6 +22,8 @@ getlimits_
 
 touch empty here || framework_failure_
 
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
 
 for mode in '' '---disable-inotify'; do
   # Use tail itself to create a background process to monitor,
@@ -32,9 +34,7 @@ for mode in '' '---disable-inotify'; do
   timeout 1 tail -f -s.1 --pid=$pid $mode here
   test $? = 124 || fail=1
 
-  # Cleanup background process
-  kill $pid
-  wait $pid
+  cleanup_
 
   # Ensure that tail --pid=PID exits with success status when PID is dead.
   # Use an unlikely-to-be-live PID
index 4d5fe51025491ad6d404ed7857f5d2cd754019ad..71a081c309baa5a363b3031b2c5b58336a8a0d8f 100755 (executable)
@@ -24,6 +24,9 @@ mkfifo_or_skip_ fifo
 echo 1 > fifo &
 echo 1 > exp || framework_failure_
 
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
 
@@ -40,9 +43,9 @@ retry_delay_ check_tail_output .1 7 || fail=1
 
 compare exp out || fail=1
 
-# Kill the still-running tail, or fail if it's gone.
-kill $pid || fail=1
+# Ensure tail is still running
+kill -0 $pid || fail=1
 
-wait $pid
+cleanup_
 
 Exit $fail
index 6aee9967b948a9f7c0a630df098e587590cb873d..a1497d90fb07df68dbf5ad74a590f125ae0e3a30 100755 (executable)
@@ -36,6 +36,9 @@ wait4lines_ ()
   [ "$(countlines_)" -ge "$elc" ] || { sleep $delay; return 1; }
 }
 
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
 
@@ -62,8 +65,7 @@ retry_delay_ wait4lines_ .1 6 1 || { cat out; fail=1; }
 echo "X" > missing              || framework_failure_
 # Wait for the expected output.
 retry_delay_ wait4lines_ .1 6 3 || { cat out; fail=1; }
-kill $pid
-wait $pid
+cleanup_
 # Expect 3 lines in the output file.
 [ "$(countlines_)" = 3 ]   || { fail=1; cat out; }
 grep -F 'cannot open' out  || { fail=1; cat out; }
@@ -80,8 +82,7 @@ retry_delay_ wait4lines_ .1 6 2 || { cat out; fail=1; }
 echo "X" > missing              || framework_failure_
 # Wait for the expected output.
 retry_delay_ wait4lines_ .1 6 4 || { cat out; fail=1; }
-kill $pid
-wait $pid
+cleanup_
 # Expect 4 lines in the output file.
 [ "$(countlines_)" = 4 ]   || { fail=1; cat out; }
 grep -F 'retry only effective for the initial open' out \
index 9f1a2010f00eeba1858791eaba106a02fc0ad72f..b5dcbbd6840a16e408007ba48e849d6d10830368 100755 (executable)
@@ -36,6 +36,9 @@ wait4lines_ ()
   [ "$(countlines_)" -ge "$elc" ] || { sleep $delay; return 1; }
 }
 
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 # speedup non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
 
@@ -50,8 +53,7 @@ retry_delay_ wait4lines_ .1 6 1 || { cat out; fail=1; }
 echo "X" > target               || framework_failure_
 # Wait for the expected output.
 retry_delay_ wait4lines_ .1 6 3 || { cat out; fail=1; }
-kill $pid
-wait $pid
+cleanup_
 # Expect 3 lines in the output file.
 [ "$(countlines_)" = 3 ]   || { fail=1; cat out; }
 grep -F 'cannot open' out  || { fail=1; cat out; }
@@ -74,8 +76,7 @@ retry_delay_ wait4lines_ .1 6 2 || { cat out; fail=1; }
 echo "X2" > target2             || framework_failure_
 # Wait for the expected output.
 retry_delay_ wait4lines_ .1 6 4 || { cat out; fail=1; }
-kill $pid
-wait $pid
+cleanup_
 # Expect 4 lines in the output file.
 [ "$(countlines_)" = 4 ]    || { fail=1; cat out; }
 grep -F 'become inacce' out || { fail=1; cat out; }
index f713a1257b87a35461b4bd906d7e243ac5496ac2..ba9f4071898a061d28c2fc94489e4fe07c889ed6 100755 (executable)
@@ -35,6 +35,9 @@ chmod 0 unreadable || framework_failure_
 tail -c0 unreadable || fail=1
 tail -n0 unreadable || fail=1
 
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 for mode in '' '---disable-inotify'; do
   for file in empty nonempty; do
     for c_or_n in c n; do
@@ -51,8 +54,7 @@ for mode in '' '---disable-inotify'; do
       # Wait up to 1.5s for tail to sleep
       retry_delay_ tail_sleeping .1 4 ||
         { echo $0: process in unexpected state: $state >&2; fail=1; }
-      kill $pid
-      wait $pid
+      cleanup_
     done
   done
 done
index ebae62bd24226268a3097392aaf42497beaffabf..071d889d6f90f3c5f0637fe99f47e40903a914b6 100755 (executable)
@@ -23,6 +23,9 @@ print_ver_ tail
 touch here || framework_failure_
 { touch unreadable && chmod a-r unreadable; } || framework_failure_
 
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
 # speedup non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
 
@@ -72,8 +75,7 @@ for mode in '' '---disable-inotify'; do
     sleep $delay
     echo NO >> l
     sleep $delay
-    kill $pid
-    wait $pid
+    cleanup_
     rm -f k l
 
     test -s tail.out