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_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_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 one 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);

Create 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_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 caller needs to make sure that there is data to read from the socket. The call will block until the socket becomes readable.

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);

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_update ()

int                 udev_monitor_filter_update          (struct udev_monitor *udev_monitor);

Update the installed filter. This might only be 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.