bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tail aborts while following by name if using inotify


From: Jim Meyering
Subject: Re: tail aborts while following by name if using inotify
Date: Tue, 29 Dec 2009 16:45:44 +0100

Giuseppe Scrivano wrote:
> Hello Jim,
>
> Jim Meyering <address@hidden> writes:
>
>> Rob Wortman wrote:
>>> I have noticed a behavioral quirk in versions of tail which use inotify.
>>> When following a file by name (using tail -F or tail --follow=name),
>>> tail will abort when a file returns after being renamed. I see that this
>>> bug was addressed in coreutils-8.1, but I still find the behavior in
>>> coreutils-8.2.
>>
>> Here's a first step: add a test to exercise the losing code.
>> The final "cat out" isn't required, but I found it handy while
>> writing the test, so left it in.
>
> this patch makes your test case pass successfully.  It must be applied
> after the three patches you have sent in another thread.
>
> Subject: [PATCH] tail: remove `fdspec' from the hash table before change its 
> key
>
> * src/tail.c (tail_forever_inotify): Avoid to modify fdspec->wd until it
> is contained in the wd_to_name hash table with a different key value.
> Once it is removed, it can be added using the new `wd' as key for the
> hash table.

Hi Giuseppe,

Thanks for the patch!
That does indeed avoid the abort.
I expect to apply it shortly.

However, while looking at it, I discovered another problem.
When tail-F'd files may be renamed, tail may fail to track
the target of a rename.  Here's a demonstration:

    $ rm -f a b; touch a b
    $ src/tail -F a b &
    [1] 19708
    ==> a <==

    ==> b <==
    $ mv a b
    src/tail: `b' has been replaced;  following end of new file
    src/tail: `a' has become inaccessible: No such file or directory
    $ echo b >> b
    $

That shows that tail is no longer displaying the content being
appended to "b".

Here's a similar test that fails with inotify-enabled tail,
yet passes with ---disable-inotify:

>From 9b1cf3db2ec18c5ff8d8a213dc58cf158b82f545 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Tue, 29 Dec 2009 16:37:04 +0100
Subject: [PATCH] tail: test for a bug in inotify-enabled tail

* tests/tail-2/F-vs-rename: New file.
* tests/Makefile.am (TESTS): Add it.
---
 tests/Makefile.am        |    1 +
 tests/tail-2/F-vs-rename |   76 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+), 0 deletions(-)
 create mode 100755 tests/tail-2/F-vs-rename

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6ef7ad8..33b9df4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -82,6 +82,7 @@ TESTS =                                               \
   cp/link-heap                                 \
   tail-2/inotify-hash-abuse                    \
   tail-2/inotify-hash-abuse2                   \
+  tail-2/F-vs-rename                           \
   tail-2/inotify-rotate                                \
   chmod/no-x                                   \
   chgrp/basic                                  \
diff --git a/tests/tail-2/F-vs-rename b/tests/tail-2/F-vs-rename
new file mode 100755
index 0000000..c216748
--- /dev/null
+++ b/tests/tail-2/F-vs-rename
@@ -0,0 +1,76 @@
+#!/bin/sh
+# demonstrate that tail -F works when renaming the tailed files
+
+# Copyright (C) 2009 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/>.
+
+if test "$VERBOSE" = yes; then
+  set -x
+  tail --version
+fi
+
+. $srcdir/test-lib.sh
+
+touch a b || framework_failure
+
+debug='---disable-inotify -s .01'
+debug=
+tail $debug -F a b > out 2>&1 & pid=$!
+
+# Wait until tail has started...
+echo x > a
+until grep '^x$' out >/dev/null 2>&1; do :; done
+
+mv a b || fail=1
+
+# Wait for the diagnostic:
+# tail: `a' has become inaccessible: No such file or directory
+until grep inaccessible out >/dev/null 2>&1; do :; done
+
+echo x > a
+# Wait up to 4s for this to appear in the output:
+# "tail: `...' has appeared;  following end of new file"
+found=false
+for i in $(seq 20); do
+  grep 'has appeared;' out > /dev/null && { found=true; break; }
+  sleep .2
+done
+$found || { echo "$0: a: unexpected delay?"; cat out; fail=1; }
+
+echo y >> b
+# Wait up to 4s for "y" to appear in the output:
+found=false
+for i in $(seq 20); do
+  case $(tr '\n' @ < out) in
+    *'@@==> b <address@hidden@') found=true; break 2;;
+  esac
+  sleep .2
+done
+$found || { echo "$0: b: unexpected delay?"; cat out; fail=1; }
+
+echo z >> a
+# Wait up to 4s for "z" to appear in the output:
+found=false
+for i in $(seq 20); do
+  case $(tr '\n' @ < out) in
+    *'@@==> a <address@hidden@') found=true; break 2;;
+  esac
+  sleep .2
+done
+$found || { echo "$0: b: unexpected delay?"; cat out; fail=1; }
+
+kill -HUP $pid
+
+Exit $fail
--
1.6.6.301.g5794




reply via email to

[Prev in Thread] Current Thread [Next in Thread]