]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tail: remove `fdspec' from the hash table before changing its key
authorGiuseppe Scrivano <gscrivano@gnu.org>
Tue, 29 Dec 2009 13:59:24 +0000 (14:59 +0100)
committerJim Meyering <meyering@redhat.com>
Tue, 29 Dec 2009 16:01:01 +0000 (17:01 +0100)
* 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

index 8e6c8ac9675ec4b97e287db7fe09d392c76d83cd..3d5e2212f11f946b25225c0f87c9a40df6d4dda6 100644 (file)
@@ -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 ();