#1039488 coreutils: tail: -f fifo broken when splicing to the fifo (uses inotify)

Package:
coreutils
Source:
coreutils
Description:
GNU core utilities
Submitter:
наб
Date:
2023-06-26 17:36:03 UTC
Severity:
normal
#1039488#5
Date:
2023-06-26 15:03:46 UTC
From:
To:
Dear Maintainer,

This came out of a linux-fsdevel@ discussion:
https://lore.kernel.org/linux-fsdevel/jbyihkyk5dtaohdwjyivambb2gffyjs3dodpofafnkkunxq7bu@jngkdxx65pux/t/#u

According to Amir, at least, it is "correct" that inotify-watching fifos
is unsupported, and tail(1) speaks of using inotify. Let's see:
-- >8 --
$ echo zupa > fifo
$ echo zupa > fifo
$ echo zupa > fifo
$ echo cupa | strace cat > fifo
...
splice(0, NULL, 1, NULL, 134217728, SPLICE_F_MOVE|SPLICE_F_MORE) = 5
splice(0, NULL, 1, NULL, 134217728, SPLICE_F_MOVE|SPLICE_F_MORE) = 0
...
$ strace < /bin/cat cat > fifo
splice(0, NULL, 1, NULL, 134217728, SPLICE_F_MOVE|SPLICE_F_MORE) = 44016
splice(0, NULL, 1, NULL, 134217728, SPLICE_F_MOVE|SPLICE_F_MORE) = 0
(a couple times until)
$ strace < /bin/cat cat > fifo
splice(0, NULL, 1, NULL, 134217728, SPLICE_F_MOVE|SPLICE_F_MORE) = 32768
splice(0, NULL, 1, NULL, 134217728, SPLICE_F_MOVE|SPLICE_F_MORE           <- sleeps here
^C
$ echo qupa > fifo                                                        <- sleeps in open
-- >8 --
yields
-- >8 --
$ tail -f fifo
zupa
zupa
zupa
-- >8 --
and at this point fifo is full but inotify hasn't returned an event and
thus service has been denied.

According to Amir, at least, this is expected behaviour, and while he
"doesn't think" it is, the only correct way of polling a pipe under Linux
I see is to fall back to classic UNIX sleep()/read().

Best,
наб

#1039488#10
Date:
2023-06-26 17:19:36 UTC
From:
To:
tail explicitly uses inotify only with regular files and fifos.
We could easily restrict that to just regular files.
You can test that with the undocumented `---disable-inotify` option
(note the three dashes).

cheers,
Pádraig

#1039488#15
Date:
2023-06-26 17:33:17 UTC
From:
To:
Hold on to your horses for now, I think I've managed to convince Amir
that splice not triggering {fa,i}notify is bad, actually, so I may
reassign this to linux if my patch or some variant of it lands
(see linux-fsdevel@ thread).
That works as expected.

Best,
наб