[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] tail: always fail when followed files become inaccessible
From: |
Pádraig Brady |
Subject: |
[PATCH] tail: always fail when followed files become inaccessible |
Date: |
Fri, 20 Dec 2024 14:51:30 +0000 |
* src/tail.c (tail forever): Exit with failure status
like we do for the inotify case. 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 | 4 ++++
src/tail.c | 2 +-
tests/tail/follow-name.sh | 21 +++++++++++++--------
tests/tail/follow-stdin.sh | 1 -
4 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/NEWS b/NEWS
index 332e862d6..aabf83bf4 100644
--- 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` will consistently exit with failure status where
+ inotify is not used, when all followed files become inaccessible.
+ [inconsistency introduced in coreutils-8.12]
+
'tail -c 4096 /dev/zero' no longer loops forever.
[This bug was present in "the beginning".]
diff --git a/src/tail.c b/src/tail.c
index 8cefb9c07..19f572556 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -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;
}
diff --git a/tests/tail/follow-name.sh b/tests/tail/follow-name.sh
index f92839c9e..8ce029c54 100755
--- a/tests/tail/follow-name.sh
+++ b/tests/tail/follow-name.sh
@@ -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_{,inotify}_forever() here
+ mv file file.unfollow || framework_failure_
+ wait $pid
+ test $? = 1 || fail=1
+ rm -f file file.unfollow || framework_failure_
+done
Exit $fail
diff --git a/tests/tail/follow-stdin.sh b/tests/tail/follow-stdin.sh
index 799353a0e..ecc8d8a79 100755
--- a/tests/tail/follow-stdin.sh
+++ b/tests/tail/follow-stdin.sh
@@ -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
--
2.47.1
- [PATCH] tail: always fail when followed files become inaccessible,
Pádraig Brady <=