diff options
36 files changed, 188 insertions, 96 deletions
@@ -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: diff --git a/tests/cp/existing-perm-race.sh b/tests/cp/existing-perm-race.sh index 30cbc6ab6..f48369cd5 100755 --- a/tests/cp/existing-perm-race.sh +++ b/tests/cp/existing-perm-race.sh @@ -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 && diff --git a/tests/cp/file-perm-race.sh b/tests/cp/file-perm-race.sh index 5057dae7b..8197962da 100755 --- a/tests/cp/file-perm-race.sh +++ b/tests/cp/file-perm-race.sh @@ -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 diff --git a/tests/cp/parent-perm-race.sh b/tests/cp/parent-perm-race.sh index 7b254b73f..c370f9e06 100755 --- a/tests/cp/parent-perm-race.sh +++ b/tests/cp/parent-perm-race.sh @@ -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 diff --git a/tests/cp/sparse-to-pipe.sh b/tests/cp/sparse-to-pipe.sh index 8fc9e09d6..2c3dcefba 100755 --- a/tests/cp/sparse-to-pipe.sh +++ b/tests/cp/sparse-to-pipe.sh @@ -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 diff --git a/tests/dd/stats.sh b/tests/dd/stats.sh index 2d3c3a8f1..e906c7486 100755 --- a/tests/dd/stats.sh +++ b/tests/dd/stats.sh @@ -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. diff --git a/tests/du/move-dir-while-traversing.sh b/tests/du/move-dir-while-traversing.sh index 7d1b58ab3..67bb34580 100755 --- a/tests/du/move-dir-while-traversing.sh +++ b/tests/du/move-dir-while-traversing.sh @@ -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; }; } diff --git a/tests/misc/cat-buf.sh b/tests/misc/cat-buf.sh index 68be86e1a..31382481a 100755 --- a/tests/misc/cat-buf.sh +++ b/tests/misc/cat-buf.sh @@ -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 } diff --git a/tests/misc/help-version.sh b/tests/misc/help-version.sh index 64d6e1642..e0dd721f9 100755 --- a/tests/misc/help-version.sh +++ b/tests/misc/help-version.sh @@ -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"; } diff --git a/tests/misc/printf-surprise.sh b/tests/misc/printf-surprise.sh index 0af64482d..20e6b0988 100755 --- a/tests/misc/printf-surprise.sh +++ b/tests/misc/printf-surprise.sh @@ -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. diff --git a/tests/misc/sort-compress-proc.sh b/tests/misc/sort-compress-proc.sh index a191a3c51..4ad42d514 100755 --- a/tests/misc/sort-compress-proc.sh +++ b/tests/misc/sort-compress-proc.sh @@ -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 diff --git a/tests/misc/sort-spinlock-abuse.sh b/tests/misc/sort-spinlock-abuse.sh index 31c5aa200..e81abf801 100755 --- a/tests/misc/sort-spinlock-abuse.sh +++ b/tests/misc/sort-spinlock-abuse.sh @@ -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: diff --git a/tests/misc/stdbuf.sh b/tests/misc/stdbuf.sh index bb1d40ca5..428d4a2f1 100755 --- a/tests/misc/stdbuf.sh +++ b/tests/misc/stdbuf.sh @@ -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 } diff --git a/tests/misc/tac-continue.sh b/tests/misc/tac-continue.sh index 9078cd58d..1389072b4 100755 --- a/tests/misc/tac-continue.sh +++ b/tests/misc/tac-continue.sh @@ -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 diff --git a/tests/misc/timeout-group.sh b/tests/misc/timeout-group.sh index 77682920b..054c5aec6 100755 --- a/tests/misc/timeout-group.sh +++ b/tests/misc/timeout-group.sh @@ -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 diff --git a/tests/mv/i-3.sh b/tests/mv/i-3.sh index 8cee6bd96..77d4a44f9 100755 --- a/tests/mv/i-3.sh +++ b/tests/mv/i-3.sh @@ -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 diff --git a/tests/rm/dangling-symlink.sh b/tests/rm/dangling-symlink.sh index 5fb50ecd1..d2e08a8ac 100755 --- a/tests/rm/dangling-symlink.sh +++ b/tests/rm/dangling-symlink.sh @@ -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 diff --git a/tests/rm/isatty.sh b/tests/rm/isatty.sh index 61148d52d..4eea4432c 100755 --- a/tests/rm/isatty.sh +++ b/tests/rm/isatty.sh @@ -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 :-) diff --git a/tests/tail-2/F-vs-missing.sh b/tests/tail-2/F-vs-missing.sh index 6622f7e42..be20ee3b8 100755 --- a/tests/tail-2/F-vs-missing.sh +++ b/tests/tail-2/F-vs-missing.sh @@ -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 diff --git a/tests/tail-2/F-vs-rename.sh b/tests/tail-2/F-vs-rename.sh index e087ec2e8..ee61a548b 100755 --- a/tests/tail-2/F-vs-rename.sh +++ b/tests/tail-2/F-vs-rename.sh @@ -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 diff --git a/tests/tail-2/append-only.sh b/tests/tail-2/append-only.sh index 9da10ae9c..2ea5df1fe 100755 --- a/tests/tail-2/append-only.sh +++ b/tests/tail-2/append-only.sh @@ -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 diff --git a/tests/tail-2/assert-2.sh b/tests/tail-2/assert-2.sh index aaf8785ae..67804feaf 100755 --- a/tests/tail-2/assert-2.sh +++ b/tests/tail-2/assert-2.sh @@ -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 diff --git a/tests/tail-2/assert.sh b/tests/tail-2/assert.sh index 906e364b5..43bd1e146 100755 --- a/tests/tail-2/assert.sh +++ b/tests/tail-2/assert.sh @@ -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 diff --git a/tests/tail-2/f-vs-rename.sh b/tests/tail-2/f-vs-rename.sh index bfd0949b4..083d71449 100755 --- a/tests/tail-2/f-vs-rename.sh +++ b/tests/tail-2/f-vs-rename.sh @@ -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 diff --git a/tests/tail-2/flush-initial.sh b/tests/tail-2/flush-initial.sh index aaeb878f5..a25bbeb1b 100755 --- a/tests/tail-2/flush-initial.sh +++ b/tests/tail-2/flush-initial.sh @@ -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 diff --git a/tests/tail-2/inotify-hash-abuse.sh b/tests/tail-2/inotify-hash-abuse.sh index d8c14c1c5..6333699c1 100755 --- a/tests/tail-2/inotify-hash-abuse.sh +++ b/tests/tail-2/inotify-hash-abuse.sh @@ -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 diff --git a/tests/tail-2/inotify-hash-abuse2.sh b/tests/tail-2/inotify-hash-abuse2.sh index b05423795..d641c241b 100755 --- a/tests/tail-2/inotify-hash-abuse2.sh +++ b/tests/tail-2/inotify-hash-abuse2.sh @@ -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 diff --git a/tests/tail-2/inotify-race.sh b/tests/tail-2/inotify-race.sh index d28f898b6..6e1a7fa40 100755 --- a/tests/tail-2/inotify-race.sh +++ b/tests/tail-2/inotify-race.sh @@ -23,6 +23,12 @@ . "${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) diff --git a/tests/tail-2/inotify-rotate-resources.sh b/tests/tail-2/inotify-rotate-resources.sh index b65ceb7c5..792236516 100755 --- a/tests/tail-2/inotify-rotate-resources.sh +++ b/tests/tail-2/inotify-rotate-resources.sh @@ -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 diff --git a/tests/tail-2/inotify-rotate.sh b/tests/tail-2/inotify-rotate.sh index be1f07e5b..638a3bbb6 100755 --- a/tests/tail-2/inotify-rotate.sh +++ b/tests/tail-2/inotify-rotate.sh @@ -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 diff --git a/tests/tail-2/pid.sh b/tests/tail-2/pid.sh index 7a4986763..b410478e5 100755 --- a/tests/tail-2/pid.sh +++ b/tests/tail-2/pid.sh @@ -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 diff --git a/tests/tail-2/pipe-f2.sh b/tests/tail-2/pipe-f2.sh index 4d5fe5102..71a081c30 100755 --- a/tests/tail-2/pipe-f2.sh +++ b/tests/tail-2/pipe-f2.sh @@ -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 diff --git a/tests/tail-2/retry.sh b/tests/tail-2/retry.sh index 6aee9967b..a1497d90f 100755 --- a/tests/tail-2/retry.sh +++ b/tests/tail-2/retry.sh @@ -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 \ diff --git a/tests/tail-2/symlink.sh b/tests/tail-2/symlink.sh index 9f1a2010f..b5dcbbd68 100755 --- a/tests/tail-2/symlink.sh +++ b/tests/tail-2/symlink.sh @@ -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; } diff --git a/tests/tail-2/tail-n0f.sh b/tests/tail-2/tail-n0f.sh index f713a1257..ba9f40718 100755 --- a/tests/tail-2/tail-n0f.sh +++ b/tests/tail-2/tail-n0f.sh @@ -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 diff --git a/tests/tail-2/wait.sh b/tests/tail-2/wait.sh index ebae62bd2..071d889d6 100755 --- a/tests/tail-2/wait.sh +++ b/tests/tail-2/wait.sh @@ -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 |