bug-coreutils
[Top][All Lists]
Advanced

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

"| tail -f" patch


From: Paul Eggert
Subject: "| tail -f" patch
Date: Thu, 22 Jul 2004 14:01:33 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

I installed the following patch to work around the "| tail -f" bug
reported recently.  This patch is like the one I posted previously,
except it adds a new (commented-out) test case covering the remaining
problem of "tail -f fifo" or "tail -f -" when standard input is a
pipe.

2004-07-22  Paul Eggert  <address@hidden>

        * src/tail.c (main): Ignore -f if no file operand is specified
        and standard input is a pipe.
        * doc/coreutils.texi (tail invocation): Do not ignore -f for
        all pipes, just for when standard input is a pipe and no
        file operand is specified.
        * tests/tail/Test.pm: Reinstate f-1 test, since we now pass.
        Add a new commented-out f-2 test, which we still fail.
        (test_vector): All f-* tests are special cases, not just f-1.
        
Index: doc/coreutils.texi
===================================================================
RCS file: /home/eggert/coreutils/cu/doc/coreutils.texi,v
retrieving revision 1.195
diff -p -u -r1.195 coreutils.texi
--- doc/coreutils.texi  6 Jul 2004 16:15:45 -0000       1.195
+++ doc/coreutils.texi  21 Jul 2004 18:46:55 -0000
@@ -2426,8 +2426,8 @@ by 1048576.
 @vindex name @r{follow option}
 @vindex descriptor @r{follow option}
 Loop forever trying to read more characters at the end of the file,
-presumably because the file is growing.  This option is ignored when
-reading from a pipe.
+presumably because the file is growing.  This option is ignored if
+no @var{file} operand is specified and standard input is a pipe.
 If more than one file is given, @command{tail} prints a header whenever it
 gets output from a different file, to indicate which file that output is
 from.
Index: src/tail.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/tail.c,v
retrieving revision 1.223
diff -p -u -r1.223 tail.c
--- src/tail.c  15 Jun 2004 18:00:58 -0000      1.223
+++ src/tail.c  21 Jul 2004 18:43:32 -0000
@@ -1687,6 +1687,15 @@ main (int argc, char **argv)
       static char *dummy_stdin = "-";
       n_files = 1;
       file = &dummy_stdin;
+
+      /* POSIX says that -f is ignored if no file operand is specified
+        and standard input is a pipe.  */
+      if (forever)
+       {
+         struct stat stats;
+         if (fstat (STDIN_FILENO, &stats) == 0 && S_ISFIFO (stats.st_mode))
+           forever = false;
+       }
     }
 
   {
Index: tests/tail/Test.pm
===================================================================
RCS file: /home/eggert/coreutils/cu/tests/tail/Test.pm,v
retrieving revision 1.11
retrieving revision 1.12
diff -p -u -r1.11 -r1.12
--- tests/tail/Test.pm  18 Feb 2002 12:35:00 -0000      1.11
+++ tests/tail/Test.pm  22 Jul 2004 20:54:53 -0000      1.12
@@ -68,7 +68,8 @@ my @tv = (
 ['n-5b', '-n  0', "y\n" x 5, '', 0],
 
 # With textutils-1.22, this failed.
-#['f-1', '-f -n 1', "a\nb\n", "b\n", 0],
+['f-1', '-f -n 1', "a\nb\n", "b\n", 0],
+#['f-2', '-f -n 1 -', "a\nb\n", "b\n", 0],
 );
 
 sub test_vector
@@ -86,7 +87,7 @@ sub test_vector
        {
          $Test::input_via{$test_name} = {REDIR => 0, PIPE => 0};
        }
-      elsif ($test_name eq 'f-1')
+      elsif ($test_name =~ /^f-/)
        {
          # Using redirection or a file would make this hang.
          $Test::input_via{$test_name} = {PIPE => 0};




reply via email to

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