[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#19760: [bug] "tail -f" with inotify fails to follow a file after a r
From: |
Pádraig Brady |
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 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 |
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.