chiark / gitweb /
libudev: clarify that udev_monitor_receive_device() is non-blocking
[elogind.git] / src / libudev / libudev-monitor.c
index 5f448e6d4765f0a086f0c0e0c327c6a61e2dbbe5..2ad9e1c3adbc1d134d36f31f8b557382dde49fab 100644 (file)
@@ -97,23 +97,6 @@ static struct udev_monitor *udev_monitor_new(struct udev *udev)
         return udev_monitor;
 }
 
-/**
- * udev_monitor_new_from_socket:
- * @udev: udev library context
- * @socket_path: unix socket path
- *
- * This function is removed from libudev and will not do anything.
- *
- * Returns: #NULL
- **/
-struct udev_monitor *udev_monitor_new_from_socket(struct udev *udev, const char *socket_path);
-_public_ struct udev_monitor *udev_monitor_new_from_socket(struct udev *udev, const char *socket_path)
-{
-        udev_err(udev, "udev_monitor_new_from_socket() does not do anything; please migrate to netlink\n");
-        errno = ENOSYS;
-        return NULL;
-}
-
 struct udev_monitor *udev_monitor_new_from_netlink_fd(struct udev *udev, const char *name, int fd)
 {
         struct udev_monitor *udev_monitor;
@@ -417,19 +400,21 @@ _public_ struct udev_monitor *udev_monitor_ref(struct udev_monitor *udev_monitor
  * the bound socket will be closed, and the resources of the monitor
  * will be released.
  *
+ * Returns: the passed udev monitor if it has still an active reference, or #NULL otherwise.
  **/
-_public_ void udev_monitor_unref(struct udev_monitor *udev_monitor)
+_public_ struct udev_monitor *udev_monitor_unref(struct udev_monitor *udev_monitor)
 {
         if (udev_monitor == NULL)
-                return;
+                return NULL;
         udev_monitor->refcount--;
         if (udev_monitor->refcount > 0)
-                return;
+                return udev_monitor;
         if (udev_monitor->sock >= 0)
                 close(udev_monitor->sock);
         udev_list_cleanup(&udev_monitor->filter_subsystem_list);
         udev_list_cleanup(&udev_monitor->filter_tag_list);
         free(udev_monitor);
+        return NULL;
 }
 
 /**
@@ -509,6 +494,11 @@ tag:
  *
  * Only socket connections with uid=0 are accepted.
  *
+ * The monitor socket is by default set to NONBLOCK. A variant of poll() on
+ * the file descriptor returned by udev_monitor_get_fd() should to be used to
+ * wake up when new devices arrive, or alternatively the file descriptor
+ * switched into blocking mode.
+ *
  * The initial refcount is 1, and needs to be decremented to
  * release the resources of the udev device.
  *
@@ -593,7 +583,7 @@ retry:
                             nlh->magic, htonl(UDEV_MONITOR_MAGIC));
                         return NULL;
                 }
-                if (nlh->properties_off+32 > buflen)
+                if (nlh->properties_off+32 > (size_t)buflen)
                         return NULL;
                 bufpos = nlh->properties_off;
         } else {