]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: shred: really fix intermittent false failure
authorPádraig Brady <P@draigBrady.com>
Thu, 4 Jun 2026 12:04:10 +0000 (13:04 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 4 Jun 2026 12:13:27 +0000 (13:13 +0100)
The previous commit is not sufficient to fix the race,
since I forgot shred now opens with O_NONBLOCK, and so cat may
not be even reading by the time shred's open() returns.

* tests/shred/fifo.sh: Put more robust synchronization in place
along the lines of what we did in commit v9.11-47-ga6ba6a23a,
using a separate fifo_writer_ to ensure the cat is reading,
before shred runs.

tests/shred/fifo.sh

index 4e7a1c487f38211970a294309b382f12805ab1cb..d89cd2ff7cc7640c4c6f9a7594de8499773417d9 100755 (executable)
@@ -58,14 +58,46 @@ compare /dev/null out || fail=1
 compare exp err || fail=1
 
 # Terminate any background processes.
-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=
+}
+
+writer_ready_()
+{
+  sleep $1
+  test -e writer-ready
+}
+
+fifo_writer_()
+{
+  exec 3>fifo &&
+  touch writer-ready &&
+  exec sleep 20
+}
 
-# Test 'shred' on a FIFO with a reader.  After the file descriptor is
-# opened, 'cat' will be unblocked.
+# Test 'shred' on a FIFO with a reader.  Use a temporary writer to
+# prove that 'cat' opened the FIFO before 'shred' runs, and keep that
+# writer open so 'cat' blocks until we close it.
+rm -f writer-ready || framework_failure_
 timeout 10 cat fifo > /dev/null & pid=$!
+fifo_writer_ & writer_pid=$!
+retry_delay_ writer_ready_ .1 6 || framework_failure_
 returns_ 1 timeout 10 shred fifo >out 2>err || fail=1
 compare /dev/null out || fail=1
 compare exp err || fail=1
+kill $writer_pid 2>/dev/null || framework_failure_
+wait $writer_pid 2>/dev/null
+writer_pid=
 wait $pid || fail=1  # on cat timeout
+pid=
 
 Exit $fail