Hi Jim,

Thanks for your feedback so far.

You wrote:
>I think the trick to doing this right is as follows:
> 
>    When a tailed file (name) disappears, and a subsequent
>    open attempt shows the new file is nonexistent or empty,
>    continue tailing the old file descriptor.
>
>    Only once the new file has content do we perform the final read
>    and then close the old descriptor.

I think I'm close. The attached patch causes `tail -F' to handle the following
case:

    touch foo
    tail -F foo &
    mv foo bar
    date >> bar

The `date' output shows up in the tail output. Also, this change only stops
reading from the old file once the new file has some content. At that time the
old file is read until EOF and closed before starting on the new file.

What do you think?

-- 
Jos Backus
jos at catnook.com
diff --git a/src/tail.c b/src/tail.c
index 2582b9d..dae5bc9 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -864,6 +864,8 @@ recheck (struct File_spec *f, bool blocking)
 		 unreadable (perms), and later becomes readable again and can
 		 be seen to be the same file (dev/ino).  Otherwise, tail prints
 		 the entire contents of the file when it becomes readable.  */
+	      ok = true;
+	      f->errnum = 0;
 	      error (0, f->errnum, _("%s has become inaccessible"),
 		     quote (pretty_name (f)));
 	    }
@@ -915,6 +917,8 @@ recheck (struct File_spec *f, bool blocking)
 	}
       else
 	{
+	  if (new_stats.st_size > 0) {
+	    (void) dump_remainder (pretty_name (f), f->fd, COPY_TO_EOF);
 	  /* Close the old one.  */
 	  close_fd (f->fd, pretty_name (f));
 
@@ -925,6 +929,7 @@ recheck (struct File_spec *f, bool blocking)
 		 quote (pretty_name (f)));
 	}
     }
+    }
   else
     {
       if (f->fd == -1)
_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to