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. >From b8148d816296ba8e6ea942c95603f6475ab68dc6 Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Mon, 28 Dec 2009 15:42:10 +0100 Subject: [PATCH] tail: add a test to exercise abort-inducing flaw in tail -F * tests/tail-2/inotify-hash-abuse: New file, derived from report by Rob Wortman. * tests/Makefile.am (TESTS): Add it. --- THANKS | 1 + tests/Makefile.am | 1 + tests/tail-2/inotify-hash-abuse | 63 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 0 deletions(-) create mode 100755 tests/tail-2/inotify-hash-abuse diff --git a/THANKS b/THANKS index 064c234..3167e90 100644 --- a/THANKS +++ b/THANKS @@ -512,6 +512,7 @@ Richard Sharman [email protected] Rick Sladkey [email protected] Rik Faith [email protected] Risto Kankkunen [email protected] +Rob Wortman [email protected] Robert H. de Vries [email protected] Robert Lindgren [email protected] Robert Millan [email protected] diff --git a/tests/Makefile.am b/tests/Makefile.am index 93d4275..35ea8b2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -80,6 +80,7 @@ TESTS = \ rm/ext3-perf \ rm/cycle \ cp/link-heap \ + tail-2/inotify-hash-abuse \ tail-2/inotify-rotate \ chmod/no-x \ chgrp/basic \ diff --git a/tests/tail-2/inotify-hash-abuse b/tests/tail-2/inotify-hash-abuse new file mode 100755 index 0000000..7517075 --- /dev/null +++ b/tests/tail-2/inotify-hash-abuse @@ -0,0 +1,63 @@ +#!/bin/sh +# Exercise an abort-inducing flaw in inotify-enabled tail -F. + +# 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 + +for i in $(seq 9); do touch $i; done || framework_failure + +tail -qF $(seq 9) > out 2>&1 & pid=$! + +# Wait until tail has started... +echo x > 9 +while :; do grep '^x$' out >/dev/null 2>&1 && break; done + +mv 1 f || fail=1 + +# Wait for this diagnostic: +# tail: `1' has become inaccessible: No such file or directory +while :; do grep 'inaccessible' out >/dev/null 2>&1 && break; done +echo a > 1 || fail=1 + +# Before the fix, the above creation of a moved-aside file +# would have caused tail to abort. In that case, appending to +# a tailed file and waiting for that new line to appear in tail's +# output would have been an infloop. +if kill -0 $pid; then + # Wait for tail to detect the changes. + echo y >> 8 + while false ; do + grep '^y$' out >/dev/null 2>&1 && break + done +fi + +wait $pid +st=$? + +case $st in + 129) ;; + *) echo tail died via unexpected signal: $st; fail=1;; +esac + +cat out + +Exit $fail -- 1.6.6.301.g5794
