[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Improved tail patch
From: |
Paul Eggert |
Subject: |
Re: Improved tail patch |
Date: |
Wed, 21 Jul 2004 11:54:35 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
Should we instead fix 'tail' to use select? Surely that would be
efficient (and easier) than all this stuff with O_NONBLOCK.
(O_NONBLOCK gives me the willies. :-)
Also, how about this small patch to fix your immediate problem? It
doesn't fix the general case, but it does fix a POSIX-conformance bug
and it fixes your test example. (It's weird that "tail -f" and "tail
-f -" have different behavior when standard input is a pipe, but
that's what POSIX explicitly requires....)
2004-07-21 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.
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
diff -p -u -r1.11 Test.pm
--- tests/tail/Test.pm 18 Feb 2002 12:35:00 -0000 1.11
+++ tests/tail/Test.pm 21 Jul 2004 18:38:07 -0000
@@ -68,7 +68,7 @@ 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],
);
sub test_vector