[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
GNU coding standards clash with POSIX for "... | tail -f"
From: |
Paul Eggert |
Subject: |
GNU coding standards clash with POSIX for "... | tail -f" |
Date: |
Thu, 29 Jun 2006 22:13:51 -0700 |
User-agent: |
Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux) |
This bug report is prompted by a defect report Geoff Clare recently
sent to the Open Group about 'tail'
<http://www.opengroup.org/sophocles/show_mail.tpl?source=L&listname=austin-review-l&id=2098>.
The GNU Coding Standards say that programs' behavior should be
independent of file type, but POSIX says that "tail" is supposed to
ignore any -f option if it has no operands and if standard input is a
pipe. The POSIX requirement is kind of strange and I don't think many
people are relying on it, but it's common practice. A consequence of
this strangeness is that GNU "tail -f FOO" and "tail -f <FOO" have
differing behaviors if FOO is a FIFO: "tail -f FOO" works, and follows
FOO, but "tail -f <FOO" does not. This is because there's no portable
way to distingish a FIFO stdin from a pipe stdin.
I propose that we resolve this clash as follows. This patch does
things the POSIX way if POSIXLY_CORRECT, and the GNU way otherwise.
I'm not a big fan of POSIXLY_CORRECT but I don't see any other way
around it here.
2006-06-29 Paul Eggert <address@hidden>
* NEWS: With no operand, 'tail -f' now silently ignores the '-f'
only if standard input is a FIFO or pipe and POSIXLY_CORRECT is set.
* doc/coreutils.texi (tail invocation): Document this.
* src/tail.c (main): Implement this.
* tests/tail/Test.pm (f-pipe-1): Renamed from f-1.
(f-pipe-0, f-pipe-2): New tests.
(test_vector): Set POSIXLY_CORRECT for the f-pipe-* tests.
Index: NEWS
===================================================================
RCS file: /fetish/cu/NEWS,v
retrieving revision 1.388
diff -p -u -r1.388 NEWS
--- NEWS 28 Jun 2006 23:49:58 -0000 1.388
+++ NEWS 30 Jun 2006 05:00:27 -0000
@@ -94,6 +94,11 @@ GNU coreutils NEWS
two hex digits), and the standard sequences (\a, \b, \f, \n, \r, \t,
\v, \", \\).
+ With no operand, 'tail -f' now silently ignores the '-f' only if
+ standard input is a FIFO or pipe and POSIXLY_CORRECT is set.
+ Formerly, it ignored the '-f' when standard input was a FIFO, pipe,
+ or socket.
+
** Scheduled for removal
ptx's --copyright (-C) option is scheduled for removal in 2007, and
Index: doc/coreutils.texi
===================================================================
RCS file: /fetish/cu/doc/coreutils.texi,v
retrieving revision 1.334
diff -p -u -r1.334 coreutils.texi
--- doc/coreutils.texi 28 Jun 2006 23:50:21 -0000 1.334
+++ doc/coreutils.texi 30 Jun 2006 05:00:30 -0000
@@ -2501,8 +2501,7 @@ 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 if
-no @var{file} operand is specified and standard input is a pipe.
+presumably because the file is growing.
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.
@@ -2534,6 +2533,10 @@ growing.
The option values @samp{descriptor} and @samp{name} may be specified only
with the long form of the option, not with @option{-f}.
address@hidden POSIXLY_CORRECT
+If @env{POSIXLY_CORRECT} is set, the @option{-f} option is ignored if
+no @var{file} operand is specified and standard input is a pipe.
+
@item -F
@opindex -F
This option is the same as @option{--follow=name --retry}. That is, tail
Index: src/tail.c
===================================================================
RCS file: /fetish/cu/src/tail.c,v
retrieving revision 1.249
diff -p -u -r1.249 tail.c
--- src/tail.c 31 Jan 2006 01:39:10 -0000 1.249
+++ src/tail.c 30 Jun 2006 05:00:30 -0000
@@ -1635,12 +1635,19 @@ main (int argc, char **argv)
file = &dummy_stdin;
/* POSIX says that -f is ignored if no file operand is specified
- and standard input is a pipe. */
- if (forever)
+ and standard input is a pipe. However, the GNU coding
+ standards say that program behavior should not depend on
+ device type, because device independence is an important
+ principle of the system's design.
+
+ Follow the POSIX requirement only if POSIXLY_CORRECT is set.
+ Ideally this would ignore -f only for pipes, but S_ISFIFO
+ succeeds for both FIFOs and pipes and we know of no portable,
+ reliable way to distinguish them. */
+ if (forever && getenv ("POSIXLY_CORRECT"))
{
struct stat stats;
- if (fstat (STDIN_FILENO, &stats) == 0
- && IS_PIPE_LIKE_FILE_TYPE (stats.st_mode))
+ if (fstat (STDIN_FILENO, &stats) == 0 && S_ISFIFO (stats.st_mode))
forever = false;
}
}
Index: tests/tail/Test.pm
===================================================================
RCS file: /fetish/cu/tests/tail/Test.pm,v
retrieving revision 1.17
diff -p -u -r1.17 Test.pm
--- tests/tail/Test.pm 1 Nov 2005 23:05:52 -0000 1.17
+++ tests/tail/Test.pm 30 Jun 2006 05:00:30 -0000
@@ -77,8 +77,9 @@ 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-2', '-f -n 1 -', "a\nb\n", "b\n", 0],
+['f-pipe-0', '-f -n 0', "a\nb\n", '', 0],
+['f-pipe-1', '-f -n 1', "a\nb\n", "b\n", 0],
+['f-pipe-2', '-f -n 2', "a\nb\n", "a\nb\n", 0],
);
sub test_vector
@@ -96,6 +97,10 @@ sub test_vector
{
$Test::env{$test_name} = ['_POSIX2_VERSION=200112'];
}
+ if ($test_name =~ /^f-pipe-/)
+ {
+ $Test::env{$test_name} = ['POSIXLY_CORRECT=1'];
+ }
# If you run the minus* tests with a FILE arg they'd hang.
# If you run the err-1 or err-3 tests with a FILE, they'd misinterpret
- GNU coding standards clash with POSIX for "... | tail -f",
Paul Eggert <=