udev_monitor

udev_monitor — device event source

Synopsis

struct              udev_monitor;
struct udev_monitor * udev_monitor_ref                  (struct udev_monitor *udev_monitor);
void                udev_monitor_unref                  (struct udev_monitor *udev_monitor);
struct udev *       udev_monitor_get_udev               (struct udev_monitor *udev_monitor);
struct udev_monitor * udev_monitor_new_from_netlink     (struct udev *udev,
                                                         const char *name);
struct udev_monitor * udev_monitor_new_from_socket      (struct udev *udev,
                                                         const char *socket_path);
int                 udev_monitor_enable_receiving       (struct udev_monitor *udev_monitor);
int                 udev_monitor_set_receive_buffer_size
                                                        (struct udev_monitor *udev_monitor,
                                                         int size);
int                 udev_monitor_get_fd                 (struct udev_monitor *udev_monitor);
struct udev_device * udev_monitor_receive_device        (struct udev_monitor *udev_monitor);
int                 udev_monitor_filter_add_match_subsystem_devtype
                                                        (struct udev_monitor *udev_monitor,
                                                         const char *subsystem,
                                                         const char *devtype);
int                 udev_monitor_filter_add_match_tag   (struct udev_monitor *udev_monitor,
                                                         const char *tag);
int                 udev_monitor_filter_update          (struct udev_monitor *udev_monitor);
int                 udev_monitor_filter_remove          (struct udev_monitor *udev_monitor);

Description

Connects to a device event source.

Details

struct udev_monitor

struct udev_monitor;

Opaque object handling an event source.


udev_monitor_ref ()

struct udev_monitor * udev_monitor_ref                  (struct udev_monitor *udev_monitor);

Take a reference of a udev monitor.

udev_monitor :

udev monitor

Returns :

the passed udev monitor

udev_monitor_unref ()

void                udev_monitor_unref                  (struct udev_monitor *udev_monitor);

Drop a reference of a udev monitor. If the refcount reaches zero, the bound socket will be closed, and the resources of the monitor will be released.

udev_monitor :

udev monitor

udev_monitor_get_udev ()

struct udev *       udev_monitor_get_udev               (struct udev_monitor *udev_monitor);

Retrieve the udev library context the monitor was created with.

udev_monitor :

udev monitor

Returns :

the udev library context

udev_monitor_new_from_netlink ()

struct udev_monitor * udev_monitor_new_from_netlink     (struct udev *udev,
                                                         const char *name);

Create new udev monitor and connect to a specified event source. Valid sources identifiers are "udev" and "kernel".

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.

The initial refcount is 1, and needs to be decremented to release the resources of the udev monitor.

udev :

udev library context

name :

name of event source

Returns :

a new udev monitor, or NULL, in case of an error

udev_monitor_new_from_socket ()

struct udev_monitor * udev_monitor_new_from_socket      (struct udev *udev,
                                                         const char *socket_path);

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.

A socket file will not be created. If it does not already exist, it will fall-back and connect to an abstract namespace socket with the given path. The permissions adjustment of a socket file, as well as the later cleanup, needs to be done by the caller.

The initial refcount is 1, and needs to be decremented to release the resources of the udev monitor.

udev :

udev library context

socket_path :

unix socket path

Returns :

a new udev monitor, or NULL, in case of an error

udev_monitor_enable_receiving ()

int                 udev_monitor_enable_receiving       (struct udev_monitor *udev_monitor);

Binds the udev_monitor socket to the event source.

udev_monitor :

the monitor which should receive events

Returns :

0 on success, otherwise a negative error value.

udev_monitor_set_receive_buffer_size ()

int                 udev_monitor_set_receive_buffer_size
                                                        (struct udev_monitor *udev_monitor,
                                                         int size);

Set the size of the kernel socket buffer. This call needs the appropriate privileges to succeed.

udev_monitor :

the monitor which should receive events

size :

the size in bytes

Returns :

0 on success, otherwise -1 on error.

udev_monitor_get_fd ()

int                 udev_monitor_get_fd                 (struct udev_monitor *udev_monitor);

Retrieve the socket file descriptor associated with the monitor.

udev_monitor :

udev monitor

Returns :

the socket file descriptor

udev_monitor_receive_device ()

struct udev_device * udev_monitor_receive_device        (struct udev_monitor *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 initial refcount is 1, and needs to be decremented to release the resources of the udev device.

udev_monitor :

udev monitor

Returns :

a new udev device, or NULL, in case of an error

udev_monitor_filter_add_match_subsystem_devtype ()

int                 udev_monitor_filter_add_match_subsystem_devtype
                                                        (struct udev_monitor *udev_monitor,
                                                         const char *subsystem,
                                                         const char *devtype);

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.

udev_monitor :

the monitor

subsystem :

the subsystem value to match the incoming devices against

devtype :

the devtype value to match the incoming devices against

Returns :

0 on success, otherwise a negative error value.

udev_monitor_filter_add_match_tag ()

int                 udev_monitor_filter_add_match_tag   (struct udev_monitor *udev_monitor,
                                                         const char *tag);

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.

udev_monitor :

the monitor

tag :

the name of a tag

Returns :

0 on success, otherwise a negative error value.

udev_monitor_filter_update ()

int                 udev_monitor_filter_update          (struct udev_monitor *udev_monitor);

Update the installed socket filter. This is only needed, if the filter was removed or changed.

udev_monitor :

monitor

Returns :

0 on success, otherwise a negative error value.

udev_monitor_filter_remove ()

int                 udev_monitor_filter_remove          (struct udev_monitor *udev_monitor);

Remove all filters from monitor.

udev_monitor :

monitor

Returns :

0 on success, otherwise a negative error value.