]> git.ipfire.org Git - thirdparty/coreutils.git/commit
tail: fix inotify startup races
authorPádraig Brady <P@draigBrady.com>
Tue, 5 May 2015 21:11:24 +0000 (22:11 +0100)
committerPádraig Brady <P@draigBrady.com>
Mon, 11 May 2015 22:03:32 +0000 (23:03 +0100)
commitcf06a872e74b45588c2e64903f7fc99cf2aafe27
tree56ab22a4de51b29f1f49f2e02f506be416b06244
parent9069f4ec850364e778c51bfa6f1ab761be67caec
tail: fix inotify startup races

The previous fixes to races in the various tail tests,
identified actual races in the tail inotify implementation.
With --follow=descriptor, if the tailed file was replaced before
the inotify watch was added, then any subsequent changes were ignored.
Similarly in --follow=name mode, all changes to a new name were
effectively ignored if that name was created after the original open()
but before the inotify_add_watch().

* src/tail.c (tail_forever_inotify): Fix 3 cases.
1. With -f, don't stop tailing when file removed before watch.
2. With -f, watch right file when file replaced before watch.
3. With -F, inspect correct file when replaced before watch.
Existing tests identify these when tail compiled with TAIL_TEST_SLEEP.
* tests/tail-2/inotify-rotate-resources.sh:
This test also identifies the issue with --follow=name
when TAIL_TEST_SLEEP is used.  Adjust so the test is immune
to such races, and also fail quicker on remote file systems.
* tests/tail-2/inotify-race2.sh: A new test using GDB,
based on inotify-race.sh, which tests the -F race
without needed recompilation with sleeps.
* tests/local.mk: Reference the new test.
* NEWS: Mention the bug.
NEWS
src/tail.c
tests/local.mk
tests/tail-2/inotify-race2.sh [new file with mode: 0755]
tests/tail-2/inotify-rotate-resources.sh