From 07f15147eb72e9c60686068ddea9c6c5b1ac62e3 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Tue, 29 Dec 2009 14:59:24 +0100 Subject: 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 --- src/tail.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/tail.c') 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 (); -- cgit v1.2.3-54-g00ecf