Pádraig Brady <[email protected]> writes:
> On 18/04/2026 05:54, Collin Funk wrote:
>> Bruno Haible via GNU coreutils General Discussion <[email protected]>
>> writes:
>>
>>> On NetBSD 10, there is one test failure (already reported for the
>>> coreutils 9.10 prerelease):
>>>
>>> FAIL: tests/tail/pipe-f2
>> This one is interesting. I haven't looked at a fix yet, but here is
>> the
>> issue.
>> When standard output is not redirected 'tail' behaves as we expect:
>> $ mkfifo fifo
>> $ echo 1 > fifo &
>> [1] 23114
>> $ ./src/timeout -v 10 ./src/tail -s.1 \
>> --max-unchanged-stats=1 -f fifo
>> 1
>> timeout: sending signal TERM to command './src/tail'
>> [1]+ Done echo 1 > fifo
>> However, when we redirect standard output nothing is printed:
>> $ echo 1 > fifo &
>> [1] 10274
>> $ ./src/timeout -v 10 ./src/tail -s.1 \
>> --max-unchanged-stats=1 -f fifo > out
>> timeout: sending signal TERM to command './src/tail'
>> [1]+ Done echo 1 > fifo
>> $ ./src/od out
>> 0000000
>> Collin
>
> Interesting. Perhaps different flushing behaviour between
> tail_forever() and tail_inotify_forever()?
> I'd put some debug to stderr at each fflush() point.
I had a similar thought, that it might have been flushing.
However, I think it is a NetBSD bug. The 'tail' program finishes reading
all of the data from the FIFO, and then calls xwrite_stdout() with the
data. At this point the 'echo' invocation should be complete since it
has no data to write. Therefore, the FIFO should have no writers. POSIX
says in this case [1]:
When attempting to read from an empty pipe or FIFO:
If no process has the pipe open for writing, read() shall return
0 to indicate end-of-file.
We then call dump_remainder() to see if there is any data left in the
file [2]. In this case there wouldn't be and we would then flush
standard output [3]. However, NetBSD never reaches that point since it
blocks on the read call in dump_remainder() [4].
I'll see if I can write an easier reproduction for the NetBSD people.
Collin
[1] https://pubs.opengroup.org/onlinepubs/9799919799/functions/read.html
[2]
https://github.com/coreutils/coreutils/blob/3cbe0491bab713e07cf0b1e51f5e3dad2b707215/src/tail.c#L1309
[3]
https://github.com/coreutils/coreutils/blob/3cbe0491bab713e07cf0b1e51f5e3dad2b707215/src/tail.c#L1326
[4]
https://github.com/coreutils/coreutils/blob/3cbe0491bab713e07cf0b1e51f5e3dad2b707215/src/tail.c#L501