]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tail: always fail when followed files become inaccessible
authorPádraig Brady <P@draigBrady.com>
Fri, 20 Dec 2024 14:28:11 +0000 (14:28 +0000)
committerPádraig Brady <P@draigBrady.com>
Sat, 21 Dec 2024 12:10:04 +0000 (12:10 +0000)
* src/tail.c (tail_forever): Without --retry, exit with failure
status like we do for the inotify case (since v8.11-15-g61de57cd2).
This is also consistent with the failure exit if no file was
accessible at tail startup.
* tests/tail/follow-stdin.sh: Tweak due to earlier exit.
* tests/tail/follow-name.sh: Test with and without inotify.
* NEWS: Mention the bug fix.

NEWS
src/tail.c
tests/tail/follow-name.sh
tests/tail/follow-stdin.sh

diff --git a/NEWS b/NEWS
index 332e862d60b282a6d3a051fefaf6489c8f07cf89..9c6f2fb0dc487a5e386cb64ff55e1c3d6d99ab6b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -32,6 +32,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   file names that are moved elsewhere within the same file system.
   [bug introduced in coreutils-8.24]
 
+  `tail --follow` without --retry, will consistently exit with failure status
+  where inotify is not used, when all followed files become inaccessible.
+  [This bug was present in "the beginning".]
+
   'tail -c 4096 /dev/zero' no longer loops forever.
   [This bug was present in "the beginning".]
 
index 8cefb9c07a968ebd39c459752d2e0c54fa9a5a7a..19f5725560c7d2e05d70cdcadca6d6f1aae90f37 100644 (file)
@@ -1305,7 +1305,7 @@ tail_forever (struct File_spec *f, size_t n_files, double sleep_interval)
 
       if (! any_live_files (f, n_files))
         {
-          error (0, 0, _("no files remaining"));
+          error (EXIT_FAILURE, 0, _("no files remaining"));
           break;
         }
 
index f92839c9e77bd3c4959d2d2776dcb89394f91a93..c22b5dd80c186af283b6af7e74e51bc5d0be1f63 100755 (executable)
@@ -29,14 +29,19 @@ returns_ 1 timeout 10 tail --follow=name no-such > out 2> err || fail=1
 sed '/inotify cannot be used/d' err > k && mv k err
 compare exp err || fail=1
 
-# Between coreutils 8.34 and 9.5 inclusive, tail would have
-# waited indefinitely when a file was moved to the same file system
+# 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; }
-touch file || framework_failure_
-timeout 10 tail --follow=name file & pid=$!
-sleep .1 # Usually in inotify loop here
-mv file file.unfollow || framework_failure_
-wait $pid
-test $? = 1 || fail=1
+fastpoll='-s.1 --max-unchanged-stats=1'  # speedup non inotify systems
+for inotify in '' '---disable-inotify'; do
+  touch file || framework_failure_
+  timeout 10 tail --follow=name $fastpoll file & pid=$!
+  sleep .1 # Usually in tail_forever{,_inotify}() here
+  mv file file.unfollow || framework_failure_
+  wait $pid
+  test $? = 1 || fail=1
+  rm -f file file.unfollow || framework_failure_
+done
 
 Exit $fail
index 799353a0e48bf3a15d93e8a78e221e2b59f6e4af..ecc8d8a79e0c9b4d51b59a56bad2eaa6041ddd45 100755 (executable)
@@ -61,7 +61,6 @@ cat <<\EOF >exp || framework_failure_
 tail: cannot fstat 'standard input'
 tail: error reading 'standard input'
 tail: no files remaining
-tail: -
 EOF
 sed 's/\(tail:.*\):.*/\1/' errt > err || framework_failure_
 compare exp err || fail=1