From: Giuseppe Scrivano Date: Tue, 29 Dec 2009 13:59:24 +0000 (+0100) Subject: tail: remove `fdspec' from the hash table before changing its key X-Git-Tag: v8.3~29 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=07f15147eb72e9c60686068ddea9c6c5b1ac62e3;p=thirdparty%2Fcoreutils.git 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 --- diff --git a/src/tail.c b/src/tail.c index 8e6c8ac967..3d5e2212f1 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 ();