[lib-doc] comments and defs for doxygen added
[platform/upstream/dbus.git] / dbus / dbus-socket-set-epoll.c
index 430a857..4cd9a56 100644 (file)
@@ -33,6 +33,7 @@
 #endif
 
 #include <errno.h>
+#include <fcntl.h>
 #include <sys/epoll.h>
 #include <unistd.h>
 
@@ -81,6 +82,21 @@ _dbus_socket_set_epoll_new (void)
 
   if (self->epfd == -1)
     {
+      int flags;
+
+      /* the size hint is ignored unless you have a rather old kernel,
+       * but must be positive on some versions, so just pick something
+       * arbitrary; it's a hint, not a limit */
+      self->epfd = epoll_create (42);
+
+      flags = fcntl (self->epfd, F_GETFD, 0);
+
+      if (flags != -1)
+        fcntl (self->epfd, F_SETFD, flags | FD_CLOEXEC);
+    }
+
+  if (self->epfd == -1)
+    {
       socket_set_epoll_free ((DBusSocketSet *) self);
       return NULL;
     }
@@ -252,8 +268,11 @@ socket_set_epoll_remove (DBusSocketSet  *set,
 {
   DBusSocketSetEpoll *self = socket_set_epoll_cast (set);
   int err;
+  /* Kernels < 2.6.9 require a non-NULL struct pointer, even though its
+   * contents are ignored */
+  struct epoll_event dummy = { 0 };
 
-  if (epoll_ctl (self->epfd, EPOLL_CTL_DEL, fd, NULL) == 0)
+  if (epoll_ctl (self->epfd, EPOLL_CTL_DEL, fd, &dummy) == 0)
     return;
 
   err = errno;