]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tail: display consistent diagnostics upon file replacement
authorPádraig Brady <P@draigBrady.com>
Tue, 9 Jun 2015 10:33:44 +0000 (11:33 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 9 Jun 2015 10:46:29 +0000 (11:46 +0100)
* src/tail.c (recheck): Display diagnostices for replaced files
even with reused inodes which is a common case.
* tests/tail-2/F-vs-missing.sh: Use correct diagnostic in comment.
* tests/tail-2/F-vs-rename.sh: Likewise.

src/tail.c
tests/tail-2/F-vs-missing.sh
tests/tail-2/F-vs-rename.sh

index 4d6b28a1956d32d31a2b3dc094fb1c2984324f2c..c062d403ff96481545dbbc742b4c02230f31ff77 100644 (file)
@@ -1019,42 +1019,37 @@ recheck (struct File_spec *f, bool blocking)
       assert (f->fd == -1);
       error (0, 0, _("%s has become accessible"), quote (pretty_name (f)));
     }
+  else if (f->fd == -1)
+    {
+      /* A new file even when inodes haven't changed as <dev,inode>
+         pairs can be reused, and we know the file was missing
+         on the previous iteration.  Note this also means the file
+         is redisplayed in --follow=name mode if renamed away from
+         and back to a monitored name.  */
+      new_file = true;
+
+      error (0, 0,
+             _("%s has appeared;  following new file"),
+             quote (pretty_name (f)));
+    }
   else if (f->ino != new_stats.st_ino || f->dev != new_stats.st_dev)
     {
+      /* File has been replaced (e.g., via log rotation) --
+        tail the new one.  */
       new_file = true;
-      if (f->fd == -1)
-        {
-          error (0, 0,
-                 _("%s has appeared;  following new file"),
-                 quote (pretty_name (f)));
-        }
-      else
-        {
-          /* Close the old one.  */
-          close_fd (f->fd, pretty_name (f));
-
-          /* File has been replaced (e.g., via log rotation) --
-             tail the new one.  */
-          error (0, 0,
-                 _("%s has been replaced;  following new file"),
-                 quote (pretty_name (f)));
-        }
+
+      error (0, 0,
+             _("%s has been replaced;  following new file"),
+             quote (pretty_name (f)));
+
+      /* Close the old one.  */
+      close_fd (f->fd, pretty_name (f));
+
     }
   else
     {
-      if (f->fd == -1)
-        {
-          /* This happens when one iteration finds the file missing,
-             then the preceding <dev,inode> pair is reused as the
-             file is recreated.  Note this also means the file is redisplayed
-             in --follow=name mode if renamed away from and back to
-             a monitored name.  */
-          new_file = true;
-        }
-      else
-        {
-          close_fd (fd, pretty_name (f));
-        }
+      /* No changes detected, so close new fd.  */
+      close_fd (fd, pretty_name (f));
     }
 
   /* FIXME: When a log is rotated, daemons tend to log to the
index be20ee3b88474194caef4b54864c266e8402f65e..54fe30a884ee58b145c001c8734211a54f20ede9 100755 (executable)
@@ -48,7 +48,7 @@ for mode in '' '---disable-inotify'; do
   (cd missing && echo x > file) || framework_failure_
 
   # Wait up to 12.7s for this to appear in the output:
-  # "tail: '...' has appeared;  following end of new file"
+  # "tail: '...' has appeared;  following new file"
   tail_re='has appeared' retry_delay_ check_tail_output .1 7 ||
     { echo "$0: file: unexpected delay?"; cat out; fail=1; }
 
index ee61a548b602f584d93ece85f81ce709bdc30c4f..06733fb41012f3c082f7b16d962896a7c88af05c 100755 (executable)
@@ -53,7 +53,7 @@ for mode in '' '---disable-inotify'; do
 
   echo x > a
   # Wait up to 12.7s for this to appear in the output:
-  # "tail: '...' has appeared;  following end of new file"
+  # "tail: '...' has appeared;  following new file"
   tail_re='has appeared' retry_delay_ check_tail_output .1 7 ||
     { echo "$0: a: unexpected delay?"; cat out; fail=1; }