1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-21 03:12:48 +02:00

tail: exit following by descriptor when no tailable file left

As a side effect of the previous commit which fixes 'tail -f --retry'
to wait for a file to appear, tail would not exit when the last file
appears untailable and gives up on this file.
This can happen, for example, when the argument file name appears
as directory.  Tail sets the 'ignore' flag of this file to true,
but instead of exiting the program, tail would continue the loop.

* src/tail.c (any_live_files): Change the function to return true
if any of the files is still tailable or if tail should continue to
try to check again.
(tail_forever): Change the condition to break the loop in the
"no files remaining" case, because now any_live_files() will care
about it, as mentioned above.
(parse_options): When --retry is used without any follow mode,
then reset reopen_inaccessible_files to false.
* tests/tail-2/retry.sh: Add test case.
This commit is contained in:
Bernhard Voelker
2013-04-20 16:34:23 +02:00
parent d461bfd274
commit 8f97679836
2 changed files with 43 additions and 6 deletions

View File

@@ -75,6 +75,24 @@ grep -F 'has appeared' out || { fail=1; cat out; }
grep '^X$' out || { fail=1; cat out; }
rm -f missing out || fail=1
# === Test:
# Ensure that tail --follow=descriptor --retry exits when the file appears
# untailable. Expect exit status 1.
timeout 10 tail -s.1 --follow=descriptor --retry missing >out 2>&1 & pid=$!
retry_delay_ wait4lines_ .1 6 2 || fail=1 # Wait for "cannot open" error.
mkdir missing || fail=1 # Create untailable 'missing'.
retry_delay_ wait4lines_ .1 6 4 || fail=1 # Wait for the expected output.
wait $pid
rc=$?
[ $( wc -l < out ) = 4 ] || { fail=1; cat out; }
grep -F 'retry only effective for the initial open' out \
|| { fail=1; cat out; }
grep -F 'cannot open' out || { fail=1; cat out; }
grep -F 'replaced with an untailable file' out || { fail=1; cat out; }
grep -F 'no files remaining' out || { fail=1; cat out; }
[ $rc = 1 ] || { fail=1; cat out; }
rm -fd missing out || fail=1
# === Test:
# Ensure that --follow=descriptor (without --retry) does *not wait* for the
# file to appear. Expect 2 lines in the output file ("cannot open" +