GNU bug report logs -
#19760
[bug] "tail -f" with inotify fails to follow a file after a rename()
Previous Next
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your message dated Tue, 31 Mar 2015 11:56:40 +0100
with message-id <551A7D68.4020901 <at> draigBrady.com>
and subject line Re: bug#19760: [bug] "tail -f" with inotify fails to follow a file after a rename()
has caused the debbugs.gnu.org bug report #19760,
regarding [bug] "tail -f" with inotify fails to follow a file after a rename()
to be marked as done.
(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)
--
19760: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=19760
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
[Message part 3 (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)]
[Message part 5 (message/rfc822, inline)]
[Message part 6 (text/plain, inline)]
On 31/03/15 07:30, Bernhard Voelker wrote:
> On 03/31/2015 05:15 AM, Pádraig Brady wrote:
>> + tail -f continues to follow changes to a file even after it's renamed.
>> + [bug introduced in coreutils-7.5]
>> +
>
> It is not 100% clear to me by this sentence what was the actual change;
> maybe a little "again" or "now" would help?
>
>> --- /dev/null
>> +++ b/tests/tail-2/f-vs-rename.sh
>> @@ -0,0 +1,51 @@
>> +#!/bin/sh
>> +# demonstrate that tail -f works when renaming the tailed files
>
> s/^d/D/; s/$/./
>
>> +# Before coreutils-8.24, tail -f a would stop tracking additions to b
>> +# after "mv a b".
>> +
>> +# Copyright (C) 2015 Free Software Foundation, Inc.
>> +
>> +# This program is free software: you can redistribute it and/or modify
>> +# it under the terms of the GNU General Public License as published by
>> +# the Free Software Foundation, either version 3 of the License, or
>> +# (at your option) any later version.
>> +
>> +# This program is distributed in the hope that it will be useful,
>> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> +# GNU General Public License for more details.
>> +
>> +# You should have received a copy of the GNU General Public License
>> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
>> +
>> +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
>> +print_ver_ tail
>> +
>> +touch a || framework_failure_
>> +
>> +debug='---disable-inotify'
>> +debug=
>> +tail $debug -f -s.1 a > out 2>&1 & pid=$!
>
> Shouldn't $debug be removed? Otherwise maybe a loop over both the
> inotify and the non-inotify mode would make sense?
>
>> +
>> +check_tail_output()
>> +{
>> + local delay="$1"
>> + grep "$tail_re" out > /dev/null ||
>> + { sleep $delay; return 1; }
>> +}
>
> Please don't discard grep's output: reading the test's log file is
> easier with this included.
>
>> +
>> +# Wait up to 12.7s for tail to start
>
> s/$/./
>
>> +echo x > a
>> +tail_re='^x$' retry_delay_ check_tail_output .1 7 || fail=1
>> +
>> +mv a b || fail=1
>> +
>> +echo y >> b
>> +# Wait up to 12.7s for "y" to appear in the output:
>> +tail_re='^y$' retry_delay_ check_tail_output .1 7 || fail=1
>> +
>> +kill $pid
>> +
>> +wait
>> +
>> +Exit $fail
>
> Otherwise +1 (including the changes in tail.c).
All good suggestions.
Latest attached.
thanks for the review!
Pádraig.
[tail-rename-desc.patch (text/x-patch, 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.