bug-coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH] tail: fix a race condition


From: Jim Meyering
Subject: Re: [PATCH] tail: fix a race condition
Date: Thu, 22 Oct 2009 09:28:19 +0200

Giuseppe Scrivano wrote:
...
> Subject: [PATCH] tests: add a new test that checks for a possible `tail' race.
>
> If new data is available between the initial read and tail registers the 
> inotify
> watch descriptors, ensure that it is read before a new event happens on the
> file.
>
> * tests/Makefile.am (TESTS): Add tail-2/inotify-race.
> * tests/tail-2/inotify-race: New file.

Thanks.
I'm merging the following, too:

The first hunk is so the test isn't mistakenly skipped
when in VERBOSE=yes mode.

There's no need to specify the full name of "tail".

I added the comment so I'll still understand what this test
was doing if I reread it in a year or so ;-)

diff --git a/tests/tail-2/inotify-race b/tests/tail-2/inotify-race
index 47129db..dcdb89b 100755
--- a/tests/tail-2/inotify-race
+++ b/tests/tail-2/inotify-race
@@ -37,29 +37,29 @@ touch tail.out || framework_failure

 ( gdb --version ) > gdb.out 2>&1
 case $(cat gdb.out) in
-    'GNU gdb'*) ;;
+    *'GNU gdb'*) ;;
     *) skip_test_ "can't run gdb";;
 esac

-
 # See if gdb works:
-
 gdb -nx --batch-silent              \
     --eval-command='break tail_forever_inotify'    \
     --eval-command='run -f file'    \
     --eval-command='quit'    \
-    $abs_top_builddir/src/tail < /dev/null > gdb.out 2>&1
+    tail < /dev/null > gdb.out 2>&1

 test -s gdb.out && skip_test_ "can't set breakpoints in tail"

-
+# Run "tail -f file", stopping to append a line just before
+# inotify initialization, and then continue.  Before the fix,
+# that just-appended line would never be output.
 timeout 10s gdb -nx --batch-silent    \
     --eval-command='break tail_forever_inotify'    \
-    --eval-command='run -f file  >> tail.out'    \
+    --eval-command='run -f file >> tail.out'    \
     --eval-command="shell echo never-seen-with-tail-7.5 >> file" \
     --eval-command='continue' \
     --eval-command='quit'    \
-    $abs_top_builddir/src/tail < /dev/null &
+    tail < /dev/null &
 pid=$!

 tail --pid=$pid -f tail.out | (read; kill $pid)




reply via email to

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