Skip to content

tail: -F does not watch the followed file itself, only its directory #16650

Open

Description

@sylvestre

tail -F only puts an inotify watch on the parent directory, never on the followed file itself. GNU 9.12 watches the file too, and removes the old watch when the file is rotated.

$ touch app.log
$ strace -f -e inotify_add_watch,inotify_rm_watch -o trace.out tail -F -s.1 app.log &
$ for i in 1 2 3; do echo line$i > app.log; sleep .5; mv app.log app.log.$i; sleep .5; done; kill %1
$ grep inotify trace.out

uutils: a single inotify_add_watch(..., "<dir>", ...), no watch on app.log, no inotify_rm_watch.

GNU 9.12:

inotify_add_watch(4, ".", IN_ATTRIB|IN_MOVED_TO|IN_CREATE|IN_DELETE|IN_DELETE_SELF) = 1
inotify_add_watch(4, "app.log", IN_MODIFY|IN_ATTRIB|IN_DELETE_SELF|IN_MOVE_SELF) = 2
inotify_add_watch(4, "app.log", IN_MODIFY|IN_ATTRIB|IN_DELETE_SELF|IN_MOVE_SELF) = 3
inotify_rm_watch(4, 2)          = 0
inotify_add_watch(4, "app.log", IN_MODIFY|IN_ATTRIB|IN_DELETE_SELF|IN_MOVE_SELF) = 4
inotify_rm_watch(4, 3)          = 0

The printed output is the same for both, but the GNU test waits for the per-file IN_MODIFY watch and its removal after a rename, so it fails.

GNU test: bash util/build-gnu.sh && bash util/run-gnu-test.sh tests/tail/inotify-rotate-resources.sh

Part of #14705

Activity

  1. lmilz commented on Nov 17, 2026

    @lmilz
    Contributor

    Hi! I'd like to work on this issue. Is anyone already working on it, or would it be okay if I gave it a try?

  2. added 2 commits that reference this issue on Nov 18, 2026
    57d7378
    ed24981
  3. added a commit that references this issue on Nov 19, 2026
    5b650d3
  4. added 2 commits that reference this issue on Nov 19, 2026
    19b2902
    02c7ed7
  5. lmilz commented on Nov 20, 2026

    @lmilz
    Contributor

    #16693 adds the per-file watch and removes it after each rotation (the strace -f reproducer above now shows the expected inotify_add_watch/inotify_rm_watch calls). tests/tail/inotify-rotate-resources.sh still fails because notify issues these syscalls from a background thread and the test's strace does not trace threads; details in the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions