coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tail: ensure -f --retry 'missing' handles truncation


From: Pádraig Brady
Subject: [PATCH] tail: ensure -f --retry 'missing' handles truncation
Date: Wed, 9 Nov 2016 17:57:35 +0000

* src/tail.c (tail_forever): The BLOCKING optimization is only
enabled for non regular files (which can't be truncated), so ensure
we don't enable that unless we've a valid st_mode.
* tests/tail-2/retry.sh: Add a test case.
* NEWS: Mention the bug fix.
---
 NEWS                  |  4 ++++
 src/tail.c            |  2 +-
 tests/tail-2/retry.sh | 13 +++++++++----
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/NEWS b/NEWS
index c223b56..d88fbd9 100644
--- a/NEWS
+++ b/NEWS
@@ -59,6 +59,10 @@ GNU coreutils NEWS                                    -*- 
outline -*-
   file systems that misreport file sizes through stale metadata.
   [This bug was present in "the beginning" but exacerbated in coreutils-8.24]
 
+  tail -f --retry 'missing file' will now process truncations of that file.
+  Previously truncation was ignored thus not outputting new data in the file.
+  [bug introduced in coreutils-5.3.0]
+
   yes now handles short writes, rather than assuming all writes complete.
   [bug introduced in coreutils-8.24]
 
diff --git a/src/tail.c b/src/tail.c
index b3018d5..66aad5b 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1111,7 +1111,7 @@ tail_forever (struct File_spec *f, size_t n_files, double 
sleep_interval)
 {
   /* Use blocking I/O as an optimization, when it's easy.  */
   bool blocking = (pid == 0 && follow_mode == Follow_descriptor
-                   && n_files == 1 && ! S_ISREG (f[0].mode));
+                   && n_files == 1 && f[0].fd != -1 && ! S_ISREG (f[0].mode));
   size_t last;
   bool writer_is_dead = false;
 
diff --git a/tests/tail-2/retry.sh b/tests/tail-2/retry.sh
index b764aa7..858909f 100755
--- a/tests/tail-2/retry.sh
+++ b/tests/tail-2/retry.sh
@@ -83,17 +83,22 @@ timeout 10 \
   tail $mode $fastpoll --follow=descriptor --retry missing >out 2>&1 & pid=$!
 # Wait for "cannot open" error.
 retry_delay_ wait4lines_ .1 6 2 || { cat out; fail=1; }
-echo "X" > missing              || framework_failure_
+echo "X1" > missing             || framework_failure_
 # Wait for the expected output.
 retry_delay_ wait4lines_ .1 6 4 || { cat out; fail=1; }
+# Ensure truncation is detected
+# tail-8.25 failed at this (as assumed non file and went into blocking mode)
+echo "X" > missing             || framework_failure_
+retry_delay_ wait4lines_ .1 6 6 || { cat out; fail=1; }
 cleanup_
-# Expect 4 lines in the output file.
-[ "$(countlines_)" = 4 ]   || { fail=1; cat out; }
+[ "$(countlines_)" = 6 ]   || { 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 'has appeared' out || { fail=1; cat out; }
-grep '^X$' out             || { fail=1; cat out; }
+grep '^X1$' out            || { fail=1; cat out; }
+grep -F 'file truncated' out || { fail=1; cat out; }
+grep '^X$' out            || { fail=1; cat out; }
 rm -f missing out          || framework_failure_
 
 # === Test:
-- 
2.5.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]