Subject: Re: bug#19760: [bug] "tail -f" with inotify fails to follow a file after a rename()

From: Bernhard Voelker <[email-masked]>
Date: Tue, 31 Mar 2015 08:30:17 +0200

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).

Thanks & have a nice day,
Berny