]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: tail: ensure --pid is responsive to intermittent input
authorPádraig Brady <P@draigBrady.com>
Sat, 16 May 2026 17:55:42 +0000 (18:55 +0100)
committerPádraig Brady <P@draigBrady.com>
Sat, 16 May 2026 22:01:16 +0000 (23:01 +0100)
* tests/tail/pid-pipe.sh: Ensure not only open() is
handled asynchronously with --pid.

tests/tail/pid-pipe.sh

index b87b6ab28f14702f2983a5ca2f6e2d15d9ab3124..b4a964e3aadd040daa1beeeee542b730f0c79319 100755 (executable)
@@ -21,16 +21,55 @@ print_ver_ tail
 
 mkfifo_or_skip_ fifo
 
+
 # Terminate any background process
-cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+cleanup_()
+{
+  for p in $pid $writer_pid; do
+    kill $p 2>/dev/null
+  done
+  for p in $pid $writer_pid; do
+    wait $p 2>/dev/null
+  done
+
+  pid=
+  writer_pid=
+}
 
 # Speedup the non inotify case
 fastpoll='-s.1 --max-unchanged-stats=1'
 
+
+# Ensure an absent FIFO writer doesn't block tail from checking --pid.
 sleep 1 & pid=$!
+returns_ 124 timeout 10 tail -f $fastpoll --pid=$pid fifo && fail=1
+cleanup_
+
 
-returns_ 124 timeout 10 tail -f $fastpoll --pid=$! fifo && fail=1
+# Ensure a silent FIFO writer doesn't block tail from checking --pid.
+rm -f writer-ready || framework_failure_
 
+writer_ready_()
+{
+  sleep $1
+  test -e writer-ready
+}
+
+# Simulate a writer that may wait a long time between writes
+silent_writer() {
+  exec 3>fifo &&
+  touch writer-ready &&
+  exec sleep 20
+}
+silent_writer & writer_pid=$!
+
+# allow fifo to open
+timeout 10 $SHELL -c ': < fifo' || framework_failure_
+retry_delay_ writer_ready_ .1 6 || framework_failure_
+
+sleep 1 & pid=$!
+returns_ 124 timeout 10 tail -f $fastpoll --pid=$pid fifo && fail=1
 cleanup_
 
+
 Exit $fail