diff options
author | Pádraig Brady <P@draigBrady.com> | 2016-11-09 19:28:23 +0000 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2016-11-10 12:43:42 +0000 |
commit | 4d45722d1160a04e4d26fd812da4e0140ad3550c (patch) | |
tree | 7262a438a66980918a438e6103563c54b80bfbf0 /tests | |
parent | 659060233ff2cff324be5cf4cc40b782068d45fd (diff) | |
download | coreutils-4d45722d1160a04e4d26fd812da4e0140ad3550c.tar.xz |
tail: only retry file open if --retry specifed
* src/tail.c (tail_file): On failure to open a file,
set ignore=true when --retry is not specified.
* tests/tail-2/assert-2.sh: Adjust to the new behavior.
* tests/tail-2/retry.sh: Add a test case. Also change
from `tail ... && fail=1` to the more robust `returns_ 1 ...`
construct which detects segfaults etc.
* NEWS: Document the fix.
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/tail-2/assert-2.sh | 2 | ||||
-rwxr-xr-x | tests/tail-2/retry.sh | 24 |
2 files changed, 22 insertions, 4 deletions
diff --git a/tests/tail-2/assert-2.sh b/tests/tail-2/assert-2.sh index 79d4254cc..03ba8e2e6 100755 --- a/tests/tail-2/assert-2.sh +++ b/tests/tail-2/assert-2.sh @@ -38,7 +38,7 @@ for mode in '' '---disable-inotify'; do rm -f a foo out touch a || framework_failure_ - tail $mode --follow=name $fastpoll a foo > out 2>&1 & pid=$! + tail $mode $fastpoll -F a foo > out 2>&1 & pid=$! # Wait up to 12.7s for tail to start. echo x > a || framework_failure_ diff --git a/tests/tail-2/retry.sh b/tests/tail-2/retry.sh index 858909f65..782992356 100755 --- a/tests/tail-2/retry.sh +++ b/tests/tail-2/retry.sh @@ -51,7 +51,7 @@ grep -F 'tail: warning: --retry ignored' out || { cat out; fail=1; } # === Test: # The same with a missing file: expect error message and exit 1. -tail --retry missing > out 2>&1 && fail=1 +returns_ 1 tail --retry missing > out 2>&1 || fail=1 [ "$(countlines_)" = 2 ] || { cat out; fail=1; } grep -F 'tail: warning: --retry ignored' out || { cat out; fail=1; } @@ -123,17 +123,35 @@ grep -F 'no files remaining' out || { fail=1; cat out; } rm -fd missing out || framework_failure_ # === Test: +# Ensure that --follow=descriptor (without --retry) does *not* try +# to open a file after an initial fail, even when there are other +# tailable files. This was an issue in <= 8.25. +touch existing || framework_failure_ +tail $mode $fastpoll --follow=descriptor missing existing >out 2>&1 & pid=$! +retry_delay_ wait4lines_ .1 6 2 || { cat out; fail=1; } +[ "$(countlines_)" = 2 ] || { fail=1; cat out; } +grep -F 'cannot open' out || { fail=1; cat out; } +echo "Y" > missing || framework_failure_ +echo "X" > existing || framework_failure_ +retry_delay_ wait4lines_ .1 6 3 || { cat out; fail=1; } +[ "$(countlines_)" = 3 ] || { fail=1; cat out; } +grep '^X$' out || { fail=1; cat out; } +grep '^Y$' out && { fail=1; cat out; } +cleanup_ +rm -f missing out existing || framework_failure_ + +# === Test: # Ensure that --follow=descriptor (without --retry) does *not wait* for the # file to appear. Expect 2 lines in the output file ("cannot open" + # "no files remaining") and exit status 1. -tail $mode --follow=descriptor missing >out 2>&1 && fail=1 +returns_ 1 tail $mode --follow=descriptor missing >out 2>&1 || fail=1 [ "$(countlines_)" = 2 ] || { fail=1; cat out; } grep -F 'cannot open' out || { fail=1; cat out; } grep -F 'no files remaining' out || { fail=1; cat out; } # === Test: # Likewise for --follow=name (without --retry). -tail $mode --follow=name missing >out 2>&1 && fail=1 +returns_ 1 tail $mode --follow=name missing >out 2>&1 || fail=1 [ "$(countlines_)" = 2 ] || { fail=1; cat out; } grep -F 'cannot open' out || { fail=1; cat out; } grep -F 'no files remaining' out || { fail=1; cat out; } |