chiark / gitweb /
libudev: monitor - update doc
[elogind.git] / libudev / libudev-monitor.c
index 5917b9e497ce03347138e688fd97dd0f78f0a2ec..31dd66827c674ee24d870b6e760ee5adbb1c40f1 100644 (file)
@@ -37,7 +37,7 @@
 /**
  * udev_monitor:
  *
- * Opaque object handling one event source.
+ * Opaque object handling an event source.
  */
 struct udev_monitor {
        struct udev *udev;
@@ -102,7 +102,12 @@ static struct udev_monitor *udev_monitor_new(struct udev *udev)
  * @udev: udev library context
  * @socket_path: unix socket path
  *
- * Create new udev monitor and connect to a specified socket. The
+ * This function should not be used in any new application. The
+ * kernel's netlink socket multiplexes messages to all interested
+ * clients. Creating custom sockets from udev to applications
+ * should be avoided.
+ *
+ * Create a new udev monitor and connect to a specified socket. The
  * path to a socket either points to an existing socket file, or if
  * the socket path starts with a '@' character, an abstract namespace
  * socket will be used.
@@ -117,7 +122,7 @@ static struct udev_monitor *udev_monitor_new(struct udev *udev)
  *
  * Returns: a new udev monitor, or #NULL, in case of an error
  **/
-struct udev_monitor *udev_monitor_new_from_socket(struct udev *udev, const char *socket_path)
+UDEV_EXPORT struct udev_monitor *udev_monitor_new_from_socket(struct udev *udev, const char *socket_path)
 {
        struct udev_monitor *udev_monitor;
        struct stat statbuf;
@@ -178,7 +183,7 @@ struct udev_monitor *udev_monitor_new_from_netlink_fd(struct udev *udev, const c
                return NULL;
 
        if (fd < 0) {
-               udev_monitor->sock = socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, NETLINK_KOBJECT_UEVENT);
+               udev_monitor->sock = socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, NETLINK_KOBJECT_UEVENT);
                if (udev_monitor->sock == -1) {
                        err(udev, "error getting socket: %m\n");
                        free(udev_monitor);
@@ -211,21 +216,18 @@ struct udev_monitor *udev_monitor_new_from_netlink_fd(struct udev *udev, const c
  * Applications should usually not connect directly to the
  * "kernel" events, because the devices might not be useable
  * at that time, before udev has configured them, and created
- * device nodes.
- *
- * Accessing devices at the same time as udev, might result
- * in unpredictable behavior.
- *
- * The "udev" events are sent out after udev has finished its
- * event processing, all rules have been processed, and needed
- * device nodes are created.
+ * device nodes. Accessing devices at the same time as udev,
+ * might result in unpredictable behavior. The "udev" events
+ * are sent out after udev has finished its event processing,
+ * all rules have been processed, and needed device nodes are
+ * created.
  *
  * The initial refcount is 1, and needs to be decremented to
  * release the resources of the udev monitor.
  *
  * Returns: a new udev monitor, or #NULL, in case of an error
  **/
-struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name)
+UDEV_EXPORT struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name)
 {
        return udev_monitor_new_from_netlink_fd(udev, name, -1);
 }
@@ -257,11 +259,12 @@ static inline void bpf_jmp(struct sock_filter *inss, unsigned int *i,
  * udev_monitor_filter_update:
  * @udev_monitor: monitor
  *
- * Update the installed filter. This might only be needed, if the filter was removed or changed.
+ * Update the installed socket filter. This is only needed,
+ * if the filter was removed or changed.
  *
  * Returns: 0 on success, otherwise a negative error value.
  */
-int udev_monitor_filter_update(struct udev_monitor *udev_monitor)
+UDEV_EXPORT int udev_monitor_filter_update(struct udev_monitor *udev_monitor)
 {
        struct sock_filter ins[512];
        struct sock_fprog filter;
@@ -373,7 +376,7 @@ int udev_monitor_allow_unicast_sender(struct udev_monitor *udev_monitor, struct
  *
  * Returns: 0 on success, otherwise a negative error value.
  */
-int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor)
+UDEV_EXPORT int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor)
 {
        int err = 0;
        const int on = 1;
@@ -430,7 +433,7 @@ int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor)
  *
  * Returns: 0 on success, otherwise -1 on error.
  */
-int udev_monitor_set_receive_buffer_size(struct udev_monitor *udev_monitor, int size)
+UDEV_EXPORT int udev_monitor_set_receive_buffer_size(struct udev_monitor *udev_monitor, int size)
 {
        if (udev_monitor == NULL)
                return -1;
@@ -454,7 +457,7 @@ int udev_monitor_disconnect(struct udev_monitor *udev_monitor)
  *
  * Returns: the passed udev monitor
  **/
-struct udev_monitor *udev_monitor_ref(struct udev_monitor *udev_monitor)
+UDEV_EXPORT struct udev_monitor *udev_monitor_ref(struct udev_monitor *udev_monitor)
 {
        if (udev_monitor == NULL)
                return NULL;
@@ -471,7 +474,7 @@ struct udev_monitor *udev_monitor_ref(struct udev_monitor *udev_monitor)
  * will be released.
  *
  **/
-void udev_monitor_unref(struct udev_monitor *udev_monitor)
+UDEV_EXPORT void udev_monitor_unref(struct udev_monitor *udev_monitor)
 {
        if (udev_monitor == NULL)
                return;
@@ -494,7 +497,7 @@ void udev_monitor_unref(struct udev_monitor *udev_monitor)
  *
  * Returns: the udev library context
  **/
-struct udev *udev_monitor_get_udev(struct udev_monitor *udev_monitor)
+UDEV_EXPORT struct udev *udev_monitor_get_udev(struct udev_monitor *udev_monitor)
 {
        if (udev_monitor == NULL)
                return NULL;
@@ -509,7 +512,7 @@ struct udev *udev_monitor_get_udev(struct udev_monitor *udev_monitor)
  *
  * Returns: the socket file descriptor
  **/
-int udev_monitor_get_fd(struct udev_monitor *udev_monitor)
+UDEV_EXPORT int udev_monitor_get_fd(struct udev_monitor *udev_monitor)
 {
        if (udev_monitor == NULL)
                return -1;
@@ -561,16 +564,14 @@ tag:
  * Receive data from the udev monitor socket, allocate a new udev
  * device, fill in the received data, and return the device.
  *
- * Only socket connections with uid=0 are accepted. The caller
- * needs to make sure that there is data to read from the socket.
- * The call will block until the socket becomes readable.
+ * Only socket connections with uid=0 are accepted.
  *
  * The initial refcount is 1, and needs to be decremented to
  * release the resources of the udev device.
  *
  * Returns: a new udev device, or #NULL, in case of an error
  **/
-struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monitor)
+UDEV_EXPORT struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monitor)
 {
        struct udev_device *udev_device;
        struct msghdr smsg;
@@ -816,14 +817,14 @@ int udev_monitor_send_device(struct udev_monitor *udev_monitor,
  * @subsystem: the subsystem value to match the incoming devices against
  * @devtype: the devtype value to match the incoming devices against
  *
- * This filer is efficiently executed inside the kernel, and libudev subscribers
+ * This filter is efficiently executed inside the kernel, and libudev subscribers
  * will usually not be woken up for devices which do not match.
  *
  * The filter must be installed before the monitor is switched to listening mode.
  *
  * Returns: 0 on success, otherwise a negative error value.
  */
-int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor *udev_monitor, const char *subsystem, const char *devtype)
+UDEV_EXPORT int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor *udev_monitor, const char *subsystem, const char *devtype)
 {
        if (udev_monitor == NULL)
                return -EINVAL;
@@ -840,14 +841,14 @@ int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor *udev_mo
  * @udev_monitor: the monitor
  * @tag: the name of a tag
  *
- * This filer is efficiently executed inside the kernel, and libudev subscribers
+ * This filter is efficiently executed inside the kernel, and libudev subscribers
  * will usually not be woken up for devices which do not match.
  *
  * The filter must be installed before the monitor is switched to listening mode.
  *
  * Returns: 0 on success, otherwise a negative error value.
  */
-int udev_monitor_filter_add_match_tag(struct udev_monitor *udev_monitor, const char *tag)
+UDEV_EXPORT int udev_monitor_filter_add_match_tag(struct udev_monitor *udev_monitor, const char *tag)
 {
        if (udev_monitor == NULL)
                return -EINVAL;
@@ -867,7 +868,7 @@ int udev_monitor_filter_add_match_tag(struct udev_monitor *udev_monitor, const c
  *
  * Returns: 0 on success, otherwise a negative error value.
  */
-int udev_monitor_filter_remove(struct udev_monitor *udev_monitor)
+UDEV_EXPORT int udev_monitor_filter_remove(struct udev_monitor *udev_monitor)
 {
        static struct sock_fprog filter = { 0, NULL };