/**
* udev_monitor:
*
- * Opaque object handling one event source.
+ * Opaque object handling an event source.
*/
struct udev_monitor {
struct udev *udev;
struct sockaddr_nl snl_destination;
struct sockaddr_un sun;
socklen_t addrlen;
- struct udev_list_node filter_subsystem_list;
- struct udev_list_node filter_tag_list;
+ struct udev_list filter_subsystem_list;
+ struct udev_list filter_tag_list;
bool bound;
};
return NULL;
udev_monitor->refcount = 1;
udev_monitor->udev = udev;
- udev_list_init(&udev_monitor->filter_subsystem_list);
- udev_list_init(&udev_monitor->filter_tag_list);
+ udev_list_init(udev, &udev_monitor->filter_subsystem_list, false);
+ udev_list_init(udev, &udev_monitor->filter_tag_list, true);
return udev_monitor;
}
* @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.
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);
* 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.
* 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.
*/
return;
if (udev_monitor->sock >= 0)
close(udev_monitor->sock);
- udev_list_cleanup_entries(udev_monitor->udev, &udev_monitor->filter_subsystem_list);
- udev_list_cleanup_entries(udev_monitor->udev, &udev_monitor->filter_tag_list);
+ udev_list_cleanup(&udev_monitor->filter_subsystem_list);
+ udev_list_cleanup(&udev_monitor->filter_tag_list);
dbg(udev_monitor->udev, "monitor %p released\n", udev_monitor);
free(udev_monitor);
}
* 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.
/* udev message needs proper version magic */
nlh = (struct udev_monitor_netlink_header *) buf;
if (nlh->magic != htonl(UDEV_MONITOR_MAGIC)) {
- err(udev_monitor->udev, "ignored a message from an invalid release of udevadm (%x != %x)\n",
+ err(udev_monitor->udev, "unrecognized message signature (%x != %x)\n",
nlh->magic, htonl(UDEV_MONITOR_MAGIC));
return NULL;
}
* @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.
return -EINVAL;
if (subsystem == NULL)
return -EINVAL;
- if (udev_list_entry_add(udev_monitor->udev,
- &udev_monitor->filter_subsystem_list, subsystem, devtype, 0) == NULL)
+ if (udev_list_entry_add(&udev_monitor->filter_subsystem_list, subsystem, devtype) == NULL)
return -ENOMEM;
return 0;
}
* @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.
return -EINVAL;
if (tag == NULL)
return -EINVAL;
- if (udev_list_entry_add(udev_monitor->udev,
- &udev_monitor->filter_tag_list, tag, NULL, 0) == NULL)
+ if (udev_list_entry_add(&udev_monitor->filter_tag_list, tag, NULL) == NULL)
return -ENOMEM;
return 0;
}
{
static struct sock_fprog filter = { 0, NULL };
- udev_list_cleanup_entries(udev_monitor->udev, &udev_monitor->filter_subsystem_list);
+ udev_list_cleanup(&udev_monitor->filter_subsystem_list);
return setsockopt(udev_monitor->sock, SOL_SOCKET, SO_ATTACH_FILTER, &filter, sizeof(filter));
}