GNU bug report logs - #19760
[bug] "tail -f" with inotify fails to follow a file after a rename()

Previous Next

Package: coreutils;

Reported by: Stephane Chazelas <stephane.chazelas <at> gmail.com>

Date: Tue, 3 Feb 2015 22:05:02 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Stephane Chazelas <stephane.chazelas <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: [bug] "tail -f" with inotify fails to follow a file after a rename()
Date: Tue, 3 Feb 2015 22:04:11 +0000
[Message part 1 (text/plain, inline)]
Hello,

On Linux, when inotify is used,

   tail -f file

follows a file only until it's renamed. After it is renamed, the
inotify watch is removed, which means tail sits there doing
nothing and any further modifications to the file are ignored.

To reproduce:

    echo 1 > file
    tail -f file &
    exec 3>> file
    echo 2 >&3
    sleep 1
    mv file file2
    sleep 1
    echo 3 >&3
    sleep 1
    : > file2

"3" is not displayed. No message about the file being truncated
either.

Work arounds:

   tail ---disable-inotify -f file
   tail -f < file # effectively disables inotify

   or rename the file with a link() followed by an unlink()
   ln file newfile && rm -f file

Note that the IN_DELETED_SELF event is not reached in
follow-descriptor mode because tail has the file open preventing
it from being deleted even after it's unlinked from the last
directory.

Path attached (on the current git head).

I don't think IN_DELETED_SELF is useful in follow-name mode
either, but I've not removed it.

-- 
Stephane
[0001-tail-fix-rename-in-follow-descriptor-mode.patch (text/x-diff, attachment)]

This bug report was last modified 10 years and 56 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.