[daemon-fix] Fixed kdbus bus address recognition
[platform/upstream/dbus.git] / bus / dir-watch-kqueue.c
index 7c18a3c..c60560f 100644 (file)
@@ -50,12 +50,6 @@ static DBusWatch *watch = NULL;
 static DBusLoop *loop = NULL;
 
 static dbus_bool_t
-_kqueue_watch_callback (DBusWatch *watch, unsigned int condition, void *data)
-{
-  return dbus_watch_handle (watch, condition);
-}
-
-static dbus_bool_t
 _handle_kqueue_watch (DBusWatch *watch, unsigned int flags, void *data)
 {
   struct kevent ev;
@@ -80,7 +74,8 @@ _handle_kqueue_watch (DBusWatch *watch, unsigned int flags, void *data)
       kq = -1;
       if (watch != NULL)
        {
-         _dbus_loop_remove_watch (loop, watch, _kqueue_watch_callback, NULL);
+         _dbus_loop_remove_watch (loop, watch);
+          _dbus_watch_invalidate (watch);
           _dbus_watch_unref (watch);
          watch = NULL;
        }
@@ -120,14 +115,14 @@ _init_kqueue (BusContext *context)
            goto out;
          }
 
-       if (!_dbus_loop_add_watch (loop, watch, _kqueue_watch_callback,
-                                   NULL, NULL))
+       if (!_dbus_loop_add_watch (loop, watch))
           {
             _dbus_warn ("Unable to add reload watch to main loop");
-           close (kq);
-           kq = -1;
+           _dbus_watch_invalidate (watch);
            _dbus_watch_unref (watch);
            watch = NULL;
+           close (kq);
+           kq = -1;
             goto out;
          }
     }
@@ -139,17 +134,18 @@ out:
 }
 
 void
-bus_set_watched_dir (BusContext *context, DBusList **directories)
+bus_set_watched_dirs (BusContext *context, DBusList **directories)
 {
   int new_fds[MAX_DIRS_TO_WATCH];
   char *new_dirs[MAX_DIRS_TO_WATCH];
   DBusList *link;
-  int i, f, fd;
+  int i, j, fd;
+  struct kevent ev;
 
   if (!_init_kqueue (context))
     goto out;
 
-  for (i = 0; i < MAX_DIRS_TO_WATCH; i++) {
+  for (i = 0; i < MAX_DIRS_TO_WATCH; i++)
     {
       new_fds[i] = -1;
       new_dirs[i] = NULL;
@@ -168,7 +164,7 @@ bus_set_watched_dir (BusContext *context, DBusList **directories)
    */
   for (i = 0; new_dirs[i]; i++)
     {
-      for (j = 0; i < num_fds; j++)
+      for (j = 0; j < num_fds; j++)
         {
           if (dirs[j] && strcmp (new_dirs[i], dirs[j]) == 0)
             {
@@ -203,17 +199,26 @@ bus_set_watched_dir (BusContext *context, DBusList **directories)
           * we may need to sleep.
           */
           fd = open (new_dirs[i], O_RDONLY);
-         if (fd < 0)
+          if (fd < 0)
             {
-              _dbus_warn ("Cannot open directory '%s'; error '%s'\n", new_dirs[i], _dbus_strerror (errno));
-             goto out;
-           }
+              if (errno != ENOENT)
+                {
+                  _dbus_warn ("Cannot open directory '%s'; error '%s'\n", new_dirs[i], _dbus_strerror (errno));
+                  goto out;
+                }
+              else
+                {
+                  new_fds[i] = -1;
+                  new_dirs[i] = NULL;
+                  continue;
+                }
+            }
 
           EV_SET (&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR,
                   NOTE_DELETE | NOTE_EXTEND | NOTE_WRITE | NOTE_RENAME, 0, 0);
           if (kevent (kq, &ev, 1, NULL, 0, NULL) == -1)
             {
-              _dbus_warn ("Cannot setup a kevent for '%s'; error '%s'\n", dir, _dbus_strerror (errno));
+              _dbus_warn ("Cannot setup a kevent for '%s'; error '%s'\n", new_dirs[i], _dbus_strerror (errno));
               close (fd);
               goto out;
             }