summaryrefslogtreecommitdiff
path: root/src/tail.c
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivano@gnu.org>2009-12-29 14:59:24 +0100
committerJim Meyering <meyering@redhat.com>2009-12-29 17:01:01 +0100
commit07f15147eb72e9c60686068ddea9c6c5b1ac62e3 (patch)
treecc819fc5e6f28385dc4a7f7308359e53aab4ec67 /src/tail.c
parented86ca7c5e4e67b59ce5cb592fef075765c7893a (diff)
downloadcoreutils-07f15147eb72e9c60686068ddea9c6c5b1ac62e3.tar.xz
tail: remove `fdspec' from the hash table before changing its key
* src/tail.c (tail_forever_inotify): Avoid modifying fdspec->wd while it is in the wd_to_name hash table. Once it is removed, it can be added using the new `wd' as key for the hash table. This fixes the abort-inducing bug reported by Rob Wortman in http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/19372
Diffstat (limited to 'src/tail.c')
-rw-r--r--src/tail.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/tail.c b/src/tail.c
index 8e6c8ac96..3d5e2212f 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1474,15 +1474,18 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
continue;
/* It's fine to add the same file more than once. */
- f[j].wd = inotify_add_watch (wd, f[j].name, inotify_wd_mask);
-
- if (f[j].wd < 0)
+ int new_wd = inotify_add_watch (wd, f[j].name, inotify_wd_mask);
+ if (new_wd < 0)
{
error (0, errno, _("cannot watch %s"), quote (f[j].name));
continue;
}
fspec = &(f[j]);
+
+ /* Remove `fspec' and re-add it using `new_fd' as its key. */
+ hash_delete (wd_to_name, fspec);
+ fspec->wd = new_wd;
if (hash_insert (wd_to_name, fspec) == NULL)
xalloc_die ();