c509d0b
--- dbus-1.2.16/bus/dir-watch-inotify.c	2009-07-14 13:06:31.000000000 -0400
c509d0b
+++ hacked/bus/dir-watch-inotify.c	2009-12-18 00:46:05.524818800 -0500
c509d0b
@@ -34,6 +34,7 @@
c509d0b
 #include <errno.h>
c509d0b
 
c509d0b
 #include <dbus/dbus-internals.h>
c509d0b
+#include <dbus/dbus-list.h>
c509d0b
 #include <dbus/dbus-watch.h>
c509d0b
 #include "dir-watch.h"
c509d0b
 
c509d0b
@@ -43,6 +44,7 @@
c509d0b
 
c509d0b
 /* use a static array to avoid handling OOM */
c509d0b
 static int wds[MAX_DIRS_TO_WATCH];
c509d0b
+static char *dirs[MAX_DIRS_TO_WATCH];
c509d0b
 static int num_wds = 0;
c509d0b
 static int inotify_fd = -1;
c509d0b
 static DBusWatch *watch = NULL;
c509d0b
@@ -90,12 +92,10 @@
c509d0b
   return TRUE;
c509d0b
 }
c509d0b
 
c509d0b
-void
c509d0b
-bus_watch_directory (const char *dir, BusContext *context)
c509d0b
+static int
c509d0b
+_init_inotify (BusContext *context)
c509d0b
 {
c509d0b
-  int wd;
c509d0b
-
c509d0b
-  _dbus_assert (dir != NULL);
c509d0b
+  int ret = 0;
c509d0b
 
c509d0b
   if (inotify_fd == -1) {
c509d0b
 #ifdef HAVE_INOTIFY_INIT1
c509d0b
@@ -112,22 +112,38 @@
c509d0b
      watch = _dbus_watch_new (inotify_fd, DBUS_WATCH_READABLE, TRUE,
c509d0b
                               _handle_inotify_watch, NULL, NULL);
c509d0b
 
c509d0b
-	if (watch == NULL)
c509d0b
-          {
c509d0b
-            _dbus_warn ("Unable to create inotify watch\n");
c509d0b
-	    goto out;
c509d0b
-	  }
c509d0b
-
c509d0b
-	if (!_dbus_loop_add_watch (loop, watch, _inotify_watch_callback,
c509d0b
-                                   NULL, NULL))
c509d0b
-          {
c509d0b
-            _dbus_warn ("Unable to add reload watch to main loop");
c509d0b
-	    _dbus_watch_unref (watch);
c509d0b
-	    watch = NULL;
c509d0b
-            goto out;
c509d0b
-	  }
c509d0b
+     if (watch == NULL)
c509d0b
+       {
c509d0b
+         _dbus_warn ("Unable to create inotify watch\n");
c509d0b
+         goto out;
c509d0b
+       }
c509d0b
+
c509d0b
+     if (!_dbus_loop_add_watch (loop, watch, _inotify_watch_callback,
c509d0b
+                                NULL, NULL))
c509d0b
+       {
c509d0b
+         _dbus_warn ("Unable to add reload watch to main loop");
c509d0b
+	 _dbus_watch_unref (watch);
c509d0b
+	 watch = NULL;
c509d0b
+         goto out;
c509d0b
+       }
c509d0b
   }
c509d0b
 
c509d0b
+  ret = 1;
c509d0b
+
c509d0b
+out:
c509d0b
+  return ret;
c509d0b
+}
c509d0b
+
c509d0b
+void
c509d0b
+bus_watch_directory (const char *dir, BusContext *context)
c509d0b
+{
c509d0b
+  int wd;
c509d0b
+
c509d0b
+  _dbus_assert (dir != NULL);
c509d0b
+
c509d0b
+  if (!_init_inotify (context))
c509d0b
+    goto out;
c509d0b
+
c509d0b
   if (num_wds >= MAX_DIRS_TO_WATCH )
c509d0b
     {
c509d0b
       _dbus_warn ("Cannot watch config directory '%s'. Already watching %d directories\n", dir, MAX_DIRS_TO_WATCH);
c509d0b
@@ -141,6 +157,7 @@
c509d0b
       goto out;
c509d0b
     }
c509d0b
 
c509d0b
+  dirs[num_wds] = strdup (dir);
c509d0b
   wds[num_wds++] = wd;
c509d0b
   _dbus_verbose ("Added watch on config directory '%s'\n", dir);
c509d0b
 
c509d0b
@@ -148,7 +165,84 @@
c509d0b
   ;
c509d0b
 }
c509d0b
 
c509d0b
-void 
c509d0b
+void
c509d0b
+bus_set_watched_dirs (BusContext *context, DBusList **directories)
c509d0b
+{
c509d0b
+  static int new_wds[MAX_DIRS_TO_WATCH];
c509d0b
+  static char *new_dirs[MAX_DIRS_TO_WATCH];
c509d0b
+  DBusList *link;
c509d0b
+  int i, j, wd;
c509d0b
+
c509d0b
+  if (!_init_inotify (context))
c509d0b
+    goto out;
c509d0b
+
c509d0b
+  for (i = 0; i < MAX_DIRS_TO_WATCH; i++)
c509d0b
+    {
c509d0b
+      new_wds[i] = -1;
c509d0b
+      new_dirs[i] = NULL;
c509d0b
+    }
c509d0b
+
c509d0b
+  i = 0;
c509d0b
+  link = _dbus_list_get_first_link (directories);
c509d0b
+  while (link != NULL)
c509d0b
+    {
c509d0b
+      new_dirs[i++] = (char *)link->data;
c509d0b
+      link = _dbus_list_get_next_link (directories, link);
c509d0b
+    }
c509d0b
+
c509d0b
+  for (i = 0; new_dirs[i]; i++)
c509d0b
+    {
c509d0b
+      for (j = 0; j < num_wds; j++)
c509d0b
+        {
c509d0b
+          if (dirs[j] && strcmp (new_dirs[i], dirs[j]) == 0)
c509d0b
+            {
c509d0b
+              new_wds[i] = wds[j];
c509d0b
+              new_dirs[i] = dirs[j];
c509d0b
+              wds[j] = -1;
c509d0b
+              dirs[j] = NULL;
c509d0b
+              break;
c509d0b
+            }
c509d0b
+        }
c509d0b
+    }
c509d0b
+
c509d0b
+  for (j = 0; j < num_wds; j++)
c509d0b
+    {
c509d0b
+      if (wds[j] != -1)
c509d0b
+        {
c509d0b
+          inotify_rm_watch (inotify_fd, wds[j]);
c509d0b
+          dbus_free (dirs[j]);
c509d0b
+          wds[j] = -1;
c509d0b
+          dirs[j] = NULL;
c509d0b
+        }
c509d0b
+    }
c509d0b
+
c509d0b
+  for (i = 0; new_dirs[i]; i++)
c509d0b
+    {
c509d0b
+      if (new_wds[i] == -1)
c509d0b
+        {
c509d0b
+          wd = inotify_add_watch (inotify_fd, new_dirs[i], IN_CLOSE_WRITE | IN_DELETE | IN_MOVED_TO | IN_MOVED_FROM);
c509d0b
+          if (wd < 0)
c509d0b
+            {
c509d0b
+              _dbus_warn ("Cannot setup inotify for '%s'; error '%s'\n", new_dirs[i], _dbus_strerror (errno));
c509d0b
+              goto out;
c509d0b
+            }
c509d0b
+          new_wds[i] = wd;
c509d0b
+          new_dirs[i] = strdup (new_dirs[i]);
c509d0b
+        }
c509d0b
+    }
c509d0b
+
c509d0b
+  num_wds = i;
c509d0b
+
c509d0b
+  for (i = 0; i < MAX_DIRS_TO_WATCH; i++)
c509d0b
+    {
c509d0b
+      wds[i] = new_wds[i];
c509d0b
+      dirs[i] = new_dirs[i];
c509d0b
+    }
c509d0b
+
c509d0b
+ out:;
c509d0b
+}
c509d0b
+
c509d0b
+void
c509d0b
 bus_drop_all_directory_watches (void)
c509d0b
 {
c509d0b
   int ret;
c509d0b
--- dbus-1.2.16/bus/dir-watch.h	2009-07-14 13:06:31.000000000 -0400
c509d0b
+++ hacked/bus/dir-watch.h	2009-12-18 00:45:47.437818936 -0500
c509d0b
@@ -32,4 +32,6 @@
c509d0b
 /* drop all the watches previously set up by bus_config_watch_directory (OS dependent, may be a NOP) */
c509d0b
 void bus_drop_all_directory_watches (void);
c509d0b
 
c509d0b
+void bus_set_watched_dirs (BusContext *context, DBusList **dirs);
c509d0b
+
c509d0b
 #endif /* DIR_WATCH_H */
c509d0b
--- dbus-1.2.16/bus/bus.c	2009-07-14 13:06:31.000000000 -0400
c509d0b
+++ hacked/bus/bus.c	2009-12-18 00:51:30.348481884 -0500
c509d0b
@@ -516,11 +516,6 @@
c509d0b
 
c509d0b
   context->activation = new_activation;
c509d0b
 
c509d0b
-  /* Drop existing conf-dir watches (if applicable) */
c509d0b
-
c509d0b
-  if (is_reload)
c509d0b
-    bus_drop_all_directory_watches ();
c509d0b
-
c509d0b
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
c509d0b
   retval = TRUE;
c509d0b
 
c509d0b
@@ -551,9 +546,7 @@
c509d0b
   _dbus_hash_table_unref (service_context_table);
c509d0b
 
c509d0b
   /* Watch all conf directories */
c509d0b
-  _dbus_list_foreach (bus_config_parser_get_conf_dirs (parser),
c509d0b
-		      (DBusForeachFunction) bus_watch_directory,
c509d0b
-		      context);
c509d0b
+  bus_set_watched_dirs (context, bus_config_parser_get_conf_dirs (parser));
c509d0b
 
c509d0b
   return TRUE;
c509d0b
 }