Skip to content

tail /dev/null --pid 0 --follow should open /dev/null with O_NONBLOCK #13109

Closed

Description

@oech3
$ strace -f -e trace=openat tail /dev/null --pid 0 --follow
...
[pid  5801] openat(AT_FDCWD, "/dev/null", O_RDONLY|O_CLOEXEC) = 6

it should be

$ strace -f -e trace=open,openat '/home/a/bin/gnu9.11/tail' /dev/null --pid 0 --follow
openat(AT_FDCWD, "/dev/null", O_RDONLY|O_NONBLOCK) = 3

Activity

  1. arbelonson-source commented on Aug 30, 2026

    @arbelonson-source
    Contributor

    Confirmed with strace (GNU 9.11, glibc):

    $ strace -f -e trace=openat,fcntl tail /tmp/f --pid 0 --follow
    openat(AT_FDCWD, "/tmp/f", O_RDONLY|O_NONBLOCK) = 3

    Two things beyond the title worth calling out, since they change what the fix needs to be:

    It isn't FIFO-specific, and it isn't cleared afterward. GNU sets O_NONBLOCK on any file — a plain regular file, not just /dev/null — whenever --pid is given, and it stays set: I only see fcntl(F_GETFL) calls after the open, never an F_SETFL that clears it. That's a different design from what's in open_file, which only applies O_NONBLOCK to FIFOs, and deliberately clears it right after opening so every subsequent read blocks normally — see the doc comment above it.

    --pid 0 should behave the same as any other pid. The call site passes settings.pid.is_some_and(|pid| pid != 0) (tail.rs:167), which excludes 0 on purpose — that's the exact case in the issue title. I checked GNU with --pid 0 and --pid 99999 side by side; both get O_NONBLOCK, so the exclusion doesn't match GNU here.

    Why I haven't opened a PR for this one: widening the condition to "any file, pid including 0" is a one-line change, but doing that without anything else would be wrong — the reason open_file clears O_NONBLOCK today is that nothing downstream in the follow loop handles EAGAIN/WouldBlock (I grepped, there's no handling anywhere in src/uu/tail). If a read genuinely returns WouldBlock — which it now could, on a FIFO or pipe with no writer ready — the current code has nowhere for that to go. GNU's own --pid polling loop is built around exactly that (O_NONBLOCK + retry on EAGAIN), so matching it properly means adding that handling, not just moving where the flag is set. Since this touches the follow loop's error handling rather than being a pure one-liner, it felt like something to describe rather than guess at blind.

    Happy to build it either way a maintainer prefers — replicate GNU's persistent-O_NONBLOCK-plus-retry shape, or leave the current clear-after-open design (which is safe) and just fix the pid != 0 exclusion as a smaller, lower-risk step.


    Investigated with AI assistance (Claude Opus 5, via Claude Code); GNU's behaviour was confirmed with strace against the installed GNU 9.11 binary.

  2. added 2 commits that reference this issue on Oct 18, 2026
    e8772ed
    0824a64
  3. added 5 commits that reference this issue on Nov 10, 2026
    b324718
    52929fa
    c529571
    5b587bc
    151c2ad
  4. added 2 commits that reference this issue on Nov 16, 2026
    f8a29fa
    0ed2023
  5. added a commit that references this issue on Nov 17, 2026
    84ad39e
  6. added 2 commits that reference this issue on Nov 17, 2026
    603a027
    0168c1d
  7. added a commit that references this issue on Nov 18, 2026
    cc77d6d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions