* tests/cat/cat-buf.sh: Always call 'wait' in case the process already
exited before being killed.
* 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/du/move-dir-while-traversing.sh: Likewise.
* tests/help/help-version.sh: Likewise.
* tests/misc/stdbuf.sh: Likewise.
* tests/mv/i-3.sh: Likewise.
* tests/printf/printf-surprise.sh: Likewise.
* tests/rm/isatty.sh: Likewise.
* tests/sort/sort-compress-proc.sh: Likewise.
* tests/sort/sort-spinlock-abuse.sh: Likewise.
* tests/tail/F-headers.sh: Likewise.
* tests/tail/F-vs-missing.sh: Likewise.
* tests/tail/F-vs-rename.sh: Likewise.
* tests/tail/append-only.sh: Likewise.
* tests/tail/assert-2.sh: Likewise.
* tests/tail/assert.sh: Likewise.
* tests/tail/debug.sh: Likewise.
* tests/tail/descriptor-vs-rename.sh: Likewise.
* tests/tail/follow-name.sh: Likewise.
* tests/tail/follow-stdin.sh: Likewise.
* tests/tail/follow-symlink.sh: Likewise.
* tests/tail/inotify-dir-recreate.sh: Likewise.
* tests/tail/inotify-hash-abuse.sh: Likewise.
* tests/tail/inotify-hash-abuse2.sh: Likewise.
* tests/tail/inotify-parent-hash.sh: Likewise.
* tests/tail/inotify-rotate.sh: Likewise.
* tests/tail/pid.sh: Likewise.
* tests/tail/pipe-f2.sh: Likewise.
* tests/tail/retry.sh: Likewise.
* tests/tail/symlink.sh: Likewise.
* tests/tail/tail-n0f.sh: Likewise.
* tests/tail/truncate.sh: Likewise.
* tests/tail/wait.sh: Likewise.
* tests/tee/tee.sh: Likewise.
* tests/timeout/timeout-group.sh: Likewise.
* tests/rm/dangling-symlink.sh: Likewise.
Also avoid redundant cleanup_ calls.
* tests/tail/flush-initial.sh: Likewise.
* tests/tail/inotify-rotate-resources.sh: Likewise.
---
 tests/cat/cat-buf.sh                   | 2 +-
 tests/cp/existing-perm-race.sh         | 2 +-
 tests/cp/file-perm-race.sh             | 2 +-
 tests/cp/parent-perm-race.sh           | 2 +-
 tests/cp/sparse-to-pipe.sh             | 2 +-
 tests/du/move-dir-while-traversing.sh  | 2 +-
 tests/help/help-version.sh             | 2 +-
 tests/misc/stdbuf.sh                   | 2 +-
 tests/mv/i-3.sh                        | 2 +-
 tests/printf/printf-surprise.sh        | 2 +-
 tests/rm/dangling-symlink.sh           | 3 +--
 tests/rm/isatty.sh                     | 2 +-
 tests/sort/sort-compress-proc.sh       | 2 +-
 tests/sort/sort-spinlock-abuse.sh      | 2 +-
 tests/tail/F-headers.sh                | 2 +-
 tests/tail/F-vs-missing.sh             | 2 +-
 tests/tail/F-vs-rename.sh              | 2 +-
 tests/tail/append-only.sh              | 2 +-
 tests/tail/assert-2.sh                 | 2 +-
 tests/tail/assert.sh                   | 2 +-
 tests/tail/debug.sh                    | 2 +-
 tests/tail/descriptor-vs-rename.sh     | 2 +-
 tests/tail/flush-initial.sh            | 3 +--
 tests/tail/follow-name.sh              | 2 +-
 tests/tail/follow-stdin.sh             | 2 +-
 tests/tail/follow-symlink.sh           | 2 +-
 tests/tail/inotify-dir-recreate.sh     | 2 +-
 tests/tail/inotify-hash-abuse.sh       | 2 +-
 tests/tail/inotify-hash-abuse2.sh      | 2 +-
 tests/tail/inotify-parent-hash.sh      | 2 +-
 tests/tail/inotify-rotate-resources.sh | 3 +--
 tests/tail/inotify-rotate.sh           | 2 +-
 tests/tail/pid.sh                      | 2 +-
 tests/tail/pipe-f2.sh                  | 2 +-
 tests/tail/retry.sh                    | 2 +-
 tests/tail/symlink.sh                  | 2 +-
 tests/tail/tail-n0f.sh                 | 2 +-
 tests/tail/truncate.sh                 | 2 +-
 tests/tail/wait.sh                     | 2 +-
 tests/tee/tee.sh                       | 2 +-
 tests/timeout/timeout-group.sh         | 2 +-
 41 files changed, 41 insertions(+), 44 deletions(-)

diff --git a/tests/cat/cat-buf.sh b/tests/cat/cat-buf.sh
index 7ffebd0fc..d5ae08d65 100755
--- a/tests/cat/cat-buf.sh
+++ b/tests/cat/cat-buf.sh
@@ -27,7 +27,7 @@ print_ver_ cat
 mkfifo_or_skip_ fifo
 
 # Terminate any background cp process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 echo 1 > exp
 
diff --git a/tests/cp/existing-perm-race.sh b/tests/cp/existing-perm-race.sh
index 71ffb4799..d50fc7182 100755
--- a/tests/cp/existing-perm-race.sh
+++ b/tests/cp/existing-perm-race.sh
@@ -40,7 +40,7 @@ chgrp $g2 fifo-copy &&
 chmod g+r fifo-copy || framework-failure
 
 # Terminate any background cp process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Copy a fifo's contents.  That way, we can examine the
 # destination permissions before they're finalized.
diff --git a/tests/cp/file-perm-race.sh b/tests/cp/file-perm-race.sh
index b65872450..46b9962b5 100755
--- a/tests/cp/file-perm-race.sh
+++ b/tests/cp/file-perm-race.sh
@@ -26,7 +26,7 @@ umask 022
 mkfifo_or_skip_ fifo
 
 # Terminate any background cp process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Copy a fifo's contents.  That way, we can examine the
 # destination permissions before they're finalized.
diff --git a/tests/cp/parent-perm-race.sh b/tests/cp/parent-perm-race.sh
index 746008c76..16323687c 100755
--- a/tests/cp/parent-perm-race.sh
+++ b/tests/cp/parent-perm-race.sh
@@ -28,7 +28,7 @@ chmod g+s d 2>/dev/null # The cp test is valid either way.
 
 # Terminate any background cp process.
 pid=
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 for attr in mode ownership
 do
diff --git a/tests/cp/sparse-to-pipe.sh b/tests/cp/sparse-to-pipe.sh
index fa9dc0982..2709f1ca9 100755
--- a/tests/cp/sparse-to-pipe.sh
+++ b/tests/cp/sparse-to-pipe.sh
@@ -22,7 +22,7 @@ print_ver_ cp
 require_sparse_support_
 
 # Terminate any background cp process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 mkfifo_or_skip_ pipe
 timeout 10 cat pipe > copy & pid=$!
diff --git a/tests/du/move-dir-while-traversing.sh 
b/tests/du/move-dir-while-traversing.sh
index 9639ac30f..b317fe190 100755
--- a/tests/du/move-dir-while-traversing.sh
+++ b/tests/du/move-dir-while-traversing.sh
@@ -72,7 +72,7 @@ for i in $(seq 99); do
 done
 
 # Terminate any background cp process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Prohibit suspension, which could otherwise cause a timeout-induced FP 
failure.
 trap '' TSTP
diff --git a/tests/help/help-version.sh b/tests/help/help-version.sh
index f6dd7a490..8cb658007 100755
--- a/tests/help/help-version.sh
+++ b/tests/help/help-version.sh
@@ -20,7 +20,7 @@
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 
 # Terminate any background processes
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 expected_failure_status_chroot=125
 expected_failure_status_env=125
diff --git a/tests/misc/stdbuf.sh b/tests/misc/stdbuf.sh
index c5c965cba..5936c2885 100755
--- a/tests/misc/stdbuf.sh
+++ b/tests/misc/stdbuf.sh
@@ -51,7 +51,7 @@ returns_ 126 env . && { returns_ 126 stdbuf -o1 . || fail=1; 
} # invalid command
 returns_ 127 stdbuf -o1 no_such || fail=1 # no such command
 
 # Terminate any background processes
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Ensure line buffering stdout takes effect
 stdbuf_linebuffer()
diff --git a/tests/mv/i-3.sh b/tests/mv/i-3.sh
index f26476e9a..159ee9e6f 100755
--- a/tests/mv/i-3.sh
+++ b/tests/mv/i-3.sh
@@ -40,7 +40,7 @@ test -r "$tty" 2>&1 \
   || skip_ '/dev/stdin is not readable'
 
 # Terminate any background processes
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 mv f g < $tty > out 2>&1 & pid=$!
 
diff --git a/tests/printf/printf-surprise.sh b/tests/printf/printf-surprise.sh
index 01ee51c1c..75fb89613 100755
--- a/tests/printf/printf-surprise.sh
+++ b/tests/printf/printf-surprise.sh
@@ -56,7 +56,7 @@ trap_sigpipe_or_skip_
 export MALLOC_PERTURB_=0
 
 # Terminate any background process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 head -c 10 fifo > out & pid=$!
 
diff --git a/tests/rm/dangling-symlink.sh b/tests/rm/dangling-symlink.sh
index d96acffa6..ca36b9a1e 100755
--- a/tests/rm/dangling-symlink.sh
+++ b/tests/rm/dangling-symlink.sh
@@ -26,7 +26,7 @@ ln -s no-file dangle
 ln -s / symlink
 
 # Terminate any background processes
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 rm ---presume-input-tty dangle symlink & pid=$!
 # The buggy rm (fileutils-4.1.9) would hang here, waiting for input.
@@ -41,6 +41,5 @@ check_files_removed() {
 }
 retry_delay_ check_files_removed .1 6 || fail=1
 
-cleanup_
 
 Exit $fail
diff --git a/tests/rm/isatty.sh b/tests/rm/isatty.sh
index c35d76772..e1763befc 100755
--- a/tests/rm/isatty.sh
+++ b/tests/rm/isatty.sh
@@ -26,7 +26,7 @@ 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; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 touch f
 chmod 0 f
diff --git a/tests/sort/sort-compress-proc.sh b/tests/sort/sort-compress-proc.sh
index 1f3b91352..9035e74cc 100755
--- a/tests/sort/sort-compress-proc.sh
+++ b/tests/sort/sort-compress-proc.sh
@@ -21,7 +21,7 @@ print_ver_ sort
 expensive_
 
 # Terminate any background processes
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 SORT_FAILURE=2
 
diff --git a/tests/sort/sort-spinlock-abuse.sh 
b/tests/sort/sort-spinlock-abuse.sh
index b2a763a76..8d1b692d9 100755
--- a/tests/sort/sort-spinlock-abuse.sh
+++ b/tests/sort/sort-spinlock-abuse.sh
@@ -30,7 +30,7 @@ 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; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 seq 100000 > in || framework_failure_
 mkfifo_or_skip_ fifo
diff --git a/tests/tail/F-headers.sh b/tests/tail/F-headers.sh
index 153a5779d..68f30544d 100755
--- a/tests/tail/F-headers.sh
+++ b/tests/tail/F-headers.sh
@@ -29,7 +29,7 @@ check_tail_output()
 }
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
diff --git a/tests/tail/F-vs-missing.sh b/tests/tail/F-vs-missing.sh
index 75a534734..8ea611cfb 100755
--- a/tests/tail/F-vs-missing.sh
+++ b/tests/tail/F-vs-missing.sh
@@ -29,7 +29,7 @@ check_tail_output()
 }
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
diff --git a/tests/tail/F-vs-rename.sh b/tests/tail/F-vs-rename.sh
index 1ee3aa860..982218eb2 100755
--- a/tests/tail/F-vs-rename.sh
+++ b/tests/tail/F-vs-rename.sh
@@ -35,7 +35,7 @@ check_tail_output() {
 }
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
diff --git a/tests/tail/append-only.sh b/tests/tail/append-only.sh
index fa24c926a..199e06875 100755
--- a/tests/tail/append-only.sh
+++ b/tests/tail/append-only.sh
@@ -22,7 +22,7 @@ print_ver_ tail
 require_root_
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 chattr_a_works=1
 touch f
diff --git a/tests/tail/assert-2.sh b/tests/tail/assert-2.sh
index 0ce619542..f07ffdc54 100755
--- a/tests/tail/assert-2.sh
+++ b/tests/tail/assert-2.sh
@@ -29,7 +29,7 @@ check_tail_output()
 }
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
diff --git a/tests/tail/assert.sh b/tests/tail/assert.sh
index d982c8a0b..2d1dda9fa 100755
--- a/tests/tail/assert.sh
+++ b/tests/tail/assert.sh
@@ -34,7 +34,7 @@ check_tail_output()
 }
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
diff --git a/tests/tail/debug.sh b/tests/tail/debug.sh
index b644166a6..c59831ec4 100755
--- a/tests/tail/debug.sh
+++ b/tests/tail/debug.sh
@@ -20,7 +20,7 @@
 print_ver_ tail
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 cleanup_fail_ ()
 {
diff --git a/tests/tail/descriptor-vs-rename.sh 
b/tests/tail/descriptor-vs-rename.sh
index 3b701610d..dc391de1e 100755
--- a/tests/tail/descriptor-vs-rename.sh
+++ b/tests/tail/descriptor-vs-rename.sh
@@ -29,7 +29,7 @@ check_tail_output()
 }
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
diff --git a/tests/tail/flush-initial.sh b/tests/tail/flush-initial.sh
index 7aed701fe..fe5ec2c0b 100755
--- a/tests/tail/flush-initial.sh
+++ b/tests/tail/flush-initial.sh
@@ -23,7 +23,7 @@ print_ver_ tail
 fastpoll='-s.1 --max-unchanged-stats=1'
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 echo line > in || framework_failure_
 # Output should be buffered since we're writing to file
@@ -39,6 +39,5 @@ tail_flush()
 }
 retry_delay_ tail_flush .1 5 || fail=1
 
-cleanup_
 
 Exit $fail
diff --git a/tests/tail/follow-name.sh b/tests/tail/follow-name.sh
index c578cb7df..e541b7cdb 100755
--- a/tests/tail/follow-name.sh
+++ b/tests/tail/follow-name.sh
@@ -32,7 +32,7 @@ compare exp err || fail=1
 # Between coreutils 8.34 and 9.5 inclusive, with inotify, tail would
 # have waited indefinitely when a file was moved to the same file system.
 # Also without inotify tail would have exited with success.
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 fastpoll='-s.1 --max-unchanged-stats=1'  # speedup non inotify systems
 for inotify in '' '---disable-inotify'; do
   touch file || framework_failure_
diff --git a/tests/tail/follow-stdin.sh b/tests/tail/follow-stdin.sh
index 28858a06c..a10931f4e 100755
--- a/tests/tail/follow-stdin.sh
+++ b/tests/tail/follow-stdin.sh
@@ -30,7 +30,7 @@ check_tail_output()
 }
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
diff --git a/tests/tail/follow-symlink.sh b/tests/tail/follow-symlink.sh
index 4cf62eb9f..de3abfece 100755
--- a/tests/tail/follow-symlink.sh
+++ b/tests/tail/follow-symlink.sh
@@ -27,7 +27,7 @@ check_tail_output()
 }
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
diff --git a/tests/tail/inotify-dir-recreate.sh 
b/tests/tail/inotify-dir-recreate.sh
index 8be4f0ee8..9b690ff3f 100755
--- a/tests/tail/inotify-dir-recreate.sh
+++ b/tests/tail/inotify-dir-recreate.sh
@@ -23,7 +23,7 @@ print_ver_ tail
 require_inotify_supported_
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 cleanup_fail_ ()
 {
diff --git a/tests/tail/inotify-hash-abuse.sh b/tests/tail/inotify-hash-abuse.sh
index cd5256fe1..44a255c42 100755
--- a/tests/tail/inotify-hash-abuse.sh
+++ b/tests/tail/inotify-hash-abuse.sh
@@ -31,7 +31,7 @@ check_tail_output()
 }
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
diff --git a/tests/tail/inotify-hash-abuse2.sh 
b/tests/tail/inotify-hash-abuse2.sh
index 590ff24ac..73365c5ed 100755
--- a/tests/tail/inotify-hash-abuse2.sh
+++ b/tests/tail/inotify-hash-abuse2.sh
@@ -21,7 +21,7 @@
 print_ver_ tail
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
diff --git a/tests/tail/inotify-parent-hash.sh 
b/tests/tail/inotify-parent-hash.sh
index ccf091af7..e6509a30f 100755
--- a/tests/tail/inotify-parent-hash.sh
+++ b/tests/tail/inotify-parent-hash.sh
@@ -28,7 +28,7 @@ check_tail_output()
     { sleep $delay; return 1; }
 }
 
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 cleanup_fail()
 {
diff --git a/tests/tail/inotify-rotate-resources.sh 
b/tests/tail/inotify-rotate-resources.sh
index c5df65965..881fdba9f 100755
--- a/tests/tail/inotify-rotate-resources.sh
+++ b/tests/tail/inotify-rotate-resources.sh
@@ -48,7 +48,7 @@ cleanup_fail()
 }
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill $pid 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 fastpoll='-s.1 --max-unchanged-stats=1'
 
@@ -99,6 +99,5 @@ for i in $(seq 2); do
     >out && >strace.out || framework_failure_ 'failed to reset output files'
 done
 
-cleanup_
 
 Exit $fail
diff --git a/tests/tail/inotify-rotate.sh b/tests/tail/inotify-rotate.sh
index 3e8bc63f1..51708b0d3 100755
--- a/tests/tail/inotify-rotate.sh
+++ b/tests/tail/inotify-rotate.sh
@@ -33,7 +33,7 @@ check_tail_output()
 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_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 cleanup_fail()
 {
diff --git a/tests/tail/pid.sh b/tests/tail/pid.sh
index 3c9a8d08c..df2c8ab52 100755
--- a/tests/tail/pid.sh
+++ b/tests/tail/pid.sh
@@ -23,7 +23,7 @@ getlimits_
 touch empty here || framework_failure_
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 for mode in '' '---disable-inotify'; do
   # Use tail itself to create a background process to monitor,
diff --git a/tests/tail/pipe-f2.sh b/tests/tail/pipe-f2.sh
index 28dd92eb5..4bc57b2f0 100755
--- a/tests/tail/pipe-f2.sh
+++ b/tests/tail/pipe-f2.sh
@@ -24,7 +24,7 @@ mkfifo_or_skip_ fifo
 echo 1 > exp || framework_failure_
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
diff --git a/tests/tail/retry.sh b/tests/tail/retry.sh
index 5ece3a2c4..f21fb8f5b 100755
--- a/tests/tail/retry.sh
+++ b/tests/tail/retry.sh
@@ -37,7 +37,7 @@ wait4lines_ ()
 }
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
diff --git a/tests/tail/symlink.sh b/tests/tail/symlink.sh
index 1044adaf9..66de22e94 100755
--- a/tests/tail/symlink.sh
+++ b/tests/tail/symlink.sh
@@ -37,7 +37,7 @@ wait4lines_ ()
 }
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # speedup non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
diff --git a/tests/tail/tail-n0f.sh b/tests/tail/tail-n0f.sh
index 82ffbf675..1b2926469 100755
--- a/tests/tail/tail-n0f.sh
+++ b/tests/tail/tail-n0f.sh
@@ -36,7 +36,7 @@ tail -c0 unreadable || fail=1
 tail -n0 unreadable || fail=1
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 for mode in '' '---disable-inotify'; do
   for file in empty nonempty; do
diff --git a/tests/tail/truncate.sh b/tests/tail/truncate.sh
index d64bfb693..a02d7f88c 100755
--- a/tests/tail/truncate.sh
+++ b/tests/tail/truncate.sh
@@ -27,7 +27,7 @@ check_tail_output()
 }
 
 # Terminate any background tail process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
diff --git a/tests/tail/wait.sh b/tests/tail/wait.sh
index ec69ff775..cd05ecd4a 100755
--- a/tests/tail/wait.sh
+++ b/tests/tail/wait.sh
@@ -29,7 +29,7 @@ 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; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # speedup non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
diff --git a/tests/tee/tee.sh b/tests/tee/tee.sh
index 5c4de6a5e..abf29246e 100755
--- a/tests/tee/tee.sh
+++ b/tests/tee/tee.sh
@@ -100,7 +100,7 @@ mkfifo_or_skip_ fifo
 
 # Ensure tee handles nonblocking output correctly
 # Terminate any background processes
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 read_fifo_delayed() {
   { sleep .1; timeout 10 dd of=/dev/null status=none; } <fifo
 }
diff --git a/tests/timeout/timeout-group.sh b/tests/timeout/timeout-group.sh
index 959cb6452..ddebe07f1 100755
--- a/tests/timeout/timeout-group.sh
+++ b/tests/timeout/timeout-group.sh
@@ -84,7 +84,7 @@ check_timeout_cmd_exiting()
 }
 
 # Terminate any background processes
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
 
 # Start above script in its own group.
 # We could use timeout for this, but that assumes an implementation.
-- 
2.55.0


Reply via email to