[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: tail -f problem
From: |
Jim Meyering |
Subject: |
Re: tail -f problem |
Date: |
Tue, 08 Sep 2009 08:43:55 +0200 |
Pádraig Brady wrote:
> Jim Meyering wrote:
>> Ulrich Drepper wrote:
>>> Jim Meyering wrote:
>>>> Thanks for the report!
>>
>> Ulrich and Ren reported that the command,
>>
>> echo foobar | tail -c3 -f
>>
>> would block indefinitely, while POSIX says that it must not.
>
> This seems to be handled already (see line 1926):
>
> echo foobar | POSIXLY_CORRECT="" tail -c3 -f
>
> Also there is the stdin_cmdline_arg bit below this new chunk.
> Is that now rendered redundant?
>
> It seems that these 3 chunks should be merged.
Good point. I missed the POSIXLY_CORRECT-handling code.
Here's an adjustment that updates the documentation, too.
The stdin_cmdline_arg part is different enough (just checking
for nameless args) and uses the result of the prior loop, so
I think it can remain, unmodified.
Thanks for the review!
Once I push this, I'll update from gnulib
and make another snapshot.
Jim
>From 43b14745e98846d18c998022b9d3b1f47215dd80 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Tue, 8 Sep 2009 08:26:22 +0200
Subject: [PATCH] tail: make the new piped-stdin test as portable as the old one
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* src/tail.c (main): Adapt piped-stdin test to use the same isapipe,
test as was used in the preceding POSIXLY_CORRECT condition.
Remove the now-subsumed POSIXLY_CORRECT test.
Reported by Pádraig Brady.
* doc/coreutils.texi (tail invocation): Document this change.
* NEWS (Changes in behavior): Reclassify, clarify.
---
NEWS | 10 ++++++----
doc/coreutils.texi | 5 +++--
src/tail.c | 31 +++++++------------------------
3 files changed, 16 insertions(+), 30 deletions(-)
diff --git a/NEWS b/NEWS
index 7d4f7e2..7805fe5 100644
--- a/NEWS
+++ b/NEWS
@@ -46,11 +46,13 @@ GNU coreutils NEWS -*-
outline -*-
cp --reflink accepts a new "auto" parameter which falls back to
a standard copy if creating a copy-on-write clone is not possible.
-** POSIX conformance
+** Changes in behavior
- tail -f now ignores "-" when stdin is a pipe or FIFO, per POSIX.
- Now, :|tail -f terminates immediately. Before, it would block indefinitely.
- [the old behavior dates back to the original implementation]
+ tail -f now ignores "-" when stdin is a pipe or FIFO.
+ tail-with-no-args now ignores -f unconditionally when stdin is a pipe or
FIFO.
+ Before, it would ignore -f only when no file argument was specified,
+ and then only when POSIXLY_CORRECT was set. Now, :|tail -f - terminates
+ immediately. Before, it would block indefinitely.
* Noteworthy changes in release 7.5 (2009-08-20) [stable]
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 86394a1..16ff613 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -2782,9 +2782,10 @@ tail invocation
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
+The @option{-f} option is ignored if
no @var{file} operand is specified and standard input is a FIFO or a pipe.
+Likewise, the @option{-f} option has no effect for any
+operand specified as @samp{-}, when standard input is a FIFO or a pipe.
@item -F
@opindex -F
diff --git a/src/tail.c b/src/tail.c
index 63874bb..81cbae0 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1922,28 +1922,6 @@ main (int argc, char **argv)
static char *dummy_stdin = (char *) "-";
n_files = 1;
file = &dummy_stdin;
-
- /* POSIX says that -f is ignored if no file operand is specified
- 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. */
-
- if (forever && getenv ("POSIXLY_CORRECT"))
- {
- struct stat st;
- int is_a_fifo_or_pipe =
- (fstat (STDIN_FILENO, &st) != 0 ? -1
- : S_ISFIFO (st.st_mode) ? 1
- : HAVE_FIFO_PIPES == 1 ? 0
- : isapipe (STDIN_FILENO));
- if (is_a_fifo_or_pipe < 0)
- error (EXIT_FAILURE, errno, _("standard input"));
- if (is_a_fifo_or_pipe)
- forever = false;
- }
}
{
@@ -1986,8 +1964,13 @@ main (int argc, char **argv)
size_t n_viable = 0;
for (i = 0; i < n_files; i++)
{
- if (STREQ (F[i].name, "-") && !F[i].ignore
- && 0 <= F[i].fd && S_ISFIFO (F[i].mode))
+ bool is_a_fifo_or_pipe =
+ (STREQ (F[i].name, "-")
+ && !F[i].ignore
+ && 0 <= F[i].fd
+ && (S_ISFIFO (F[i].mode)
+ || (HAVE_FIFO_PIPES != 1 && isapipe (F[i].fd))));
+ if (is_a_fifo_or_pipe)
F[i].ignore = true;
else
++n_viable;
--
1.6.4.2.419.gab238