bug-coreutils
[Top][All Lists]
Advanced

[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, 15 Sep 2009 15:50:27 +0200

Pádraig Brady wrote:
> Jim Meyering wrote:
>>
>> diff --git a/src/tail.c b/src/tail.c
>> @@ -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;
>
> Note that old code you moved down has an issue under ksh
> which causes tail-2/pipe-f to fail.
> I.E. this will wait under ksh for both original and new tail:
>
>   echo foobar | POSIXLY_CORRECT="" tail -c3 -f

Interesting.
I didn't realize (or remember ;-) that ksh pipes were different.

Using my just-modified stat:

  $ for i in sh zsh bash ksh; do \
    printf "$i: "; $i -c ':|./stat --format=%F -';done
  sh: fifo
  zsh: fifo
  bash: fifo
  ksh: socket

Note that the posix spec says how -f must act:

  -f  If the input file is a regular file or if the file operand
      specifies a FIFO, do not terminate after the last line of the
      input file has been copied, but read and copy further bytes from
      the input file when they become available.
      If no file operand is                                               <<
      specified and standard input is a pipe or FIFO, the -f option shall <<
      be ignored. If the input file is not a FIFO, pipe, or regular file, <<
      it is unspecified whether or not the -f option shall be ignored.    <<

Which makes your suggested change a conformance bug fix.

> This seems to be because the HAVE_FIFO_PIPES compile time test,
> which assumes the shell is going to call pipe().

Right.

> BTW, tail is the only coreutils user of isapipe().
>
> Could tail in this case just do:
>
> S_ISFIFO (F[i].mode) || S_ISSOCK (F[i].mode)

I suppose that would work.
Do you feel like making the change?
If so, please remove isapipe from bootstrap.conf.




reply via email to

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