summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2022-12-14 12:19:31 -0500
committerTavian Barnes <tavianator@tavianator.com>2022-12-14 12:19:31 -0500
commitf21a9340cd0c615ead1954eb6b93845a4f8c0897 (patch)
treec96b2e3a7c30ff62fa560566ece302fc8f9823be
parentf3ba6a3e40d72e00d13e943d9338b60b4bee2e40 (diff)
downloadbfs-f21a9340cd0c615ead1954eb6b93845a4f8c0897.tar.xz
tests/posix/readdir_error: Fix flakiness
-rw-r--r--tests/posix/readdir_error.sh30
1 files changed, 23 insertions, 7 deletions
diff --git a/tests/posix/readdir_error.sh b/tests/posix/readdir_error.sh
index cca71f0..ce06723 100644
--- a/tests/posix/readdir_error.sh
+++ b/tests/posix/readdir_error.sh
@@ -1,21 +1,37 @@
+skip_unless test "$UNAME" = "Linux"
+
clean_scratch
-mkfifo scratch/{pid,hup}
+mkfifo scratch/{fever,pid,wait,running}
(
# Create a zombie process
- echo >/dev/null &
+ cat scratch/fever >/dev/null &
# Write the PID to scratch/pid
echo $! >scratch/pid
- # Don't wait on the processes
- exec cat scratch/hup >/dev/null
+ # Don't wait on the zombie process
+ exec cat scratch/wait scratch/fever >scratch/running
) &
-# Kill cat on exit
-trap "echo >scratch/hup" EXIT
+# Kill the parent cat on exit
+trap "kill -9 %1" EXIT
-# Read the zombie PID
+# Read the child PID
read -r pid <scratch/pid
+# Make sure the parent cat is running before we kill the child, because bash
+# will wait() on its children
+echo >scratch/wait &
+read -r _ <scratch/running
+
+# Turn the child into a zombie
+kill -9 "$pid"
+
+# Wait until it's really a zombie
+state=R
+while [ "$state" != "Z" ]; do
+ read -r _ _ state _ <"/proc/$pid/stat" || exit 1
+done
+
# On Linux, open(/proc/$pid/net) will succeed but readdir() will fail
skip_unless test -r "/proc/$pid/net"
fail invoke_bfs "/proc/$pid/net" >/dev/null