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


View this message in rfc822 format

From: Pádraig Brady <P <at> draigBrady.com>
To: Stephane Chazelas <stephane.chazelas <at> gmail.com>,  19760 <at> debbugs.gnu.org
Subject: bug#19760: [bug] "tail -f" with inotify fails to follow a file after a rename()
Date: Tue, 03 Feb 2015 23:30:34 +0000
On 03/02/15 22:04, Stephane Chazelas wrote:
> 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.
> 
> Patch attached (on the current git head).

Ouch. The patch makes sense on first glance,
and all existing tests pass with it.
I'll check some more and add a test.

thanks!
Pádraig.




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.