/**
* udev_monitor:
*
- * Opaque object handling one event source.
+ * Opaque object handling an event source.
*/
struct udev_monitor {
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.
*
* 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;
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.
*
* 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);
}
* 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;
*
* 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;
*
* 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;
*
* 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;
* 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;
*
* 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;
*
* 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;
* 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;
* @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;
* @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;
*
* 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 };