#include "device-private.h"
#include "device-util.h"
#include "libudev-device-internal.h"
-#include "libudev-private.h"
#include "string-util.h"
/**
return _MONITOR_NETLINK_GROUP_INVALID;
}
-struct udev_monitor *udev_monitor_new_from_netlink_fd(struct udev *udev, const char *name, int fd) {
- _cleanup_(sd_device_monitor_unrefp) sd_device_monitor *m = NULL;
- _cleanup_(udev_monitor_unrefp) struct udev_monitor *udev_monitor = NULL;
- MonitorNetlinkGroup g;
- int r;
-
- g = monitor_netlink_group_from_string(name);
- if (g < 0) {
- errno = EINVAL;
- return NULL;
- }
-
- r = device_monitor_new_full(&m, g, fd);
- if (r < 0) {
- errno = -r;
- return NULL;
- }
-
- udev_monitor = new(struct udev_monitor, 1);
- if (!udev_monitor) {
- errno = ENOMEM;
- return NULL;
- }
-
- *udev_monitor = (struct udev_monitor) {
- .udev = udev,
- .n_ref = 1,
- .monitor = TAKE_PTR(m),
- };
-
- return TAKE_PTR(udev_monitor);
-}
-
/**
* udev_monitor_new_from_netlink:
* @udev: udev library context
* 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
+ * "kernel" events, because the devices might not be usable
* 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
* Returns: a new udev monitor, or #NULL, in case of an error
**/
_public_ struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name) {
- return udev_monitor_new_from_netlink_fd(udev, name, -1);
+ _cleanup_(sd_device_monitor_unrefp) sd_device_monitor *m = NULL;
+ struct udev_monitor *udev_monitor;
+ MonitorNetlinkGroup g;
+ int r;
+
+ g = monitor_netlink_group_from_string(name);
+ if (g < 0)
+ return_with_errno(NULL, EINVAL);
+
+ r = device_monitor_new_full(&m, g, -1);
+ if (r < 0)
+ return_with_errno(NULL, r);
+
+ udev_monitor = new(struct udev_monitor, 1);
+ if (!udev_monitor)
+ return_with_errno(NULL, ENOMEM);
+
+ *udev_monitor = (struct udev_monitor) {
+ .udev = udev,
+ .n_ref = 1,
+ .monitor = TAKE_PTR(m),
+ };
+
+ return udev_monitor;
}
/**
return sd_device_monitor_filter_update(udev_monitor->monitor);
}
-int udev_monitor_allow_unicast_sender(struct udev_monitor *udev_monitor, struct udev_monitor *sender) {
- assert_return(udev_monitor, -EINVAL);
- assert_return(sender, -EINVAL);
-
- return device_monitor_allow_unicast_sender(udev_monitor->monitor, sender->monitor);
-}
-
/**
* udev_monitor_enable_receiving:
* @udev_monitor: the monitor which should receive events
return sd_device_monitor_set_receive_buffer_size(udev_monitor->monitor, (size_t) size);
}
-int udev_monitor_disconnect(struct udev_monitor *udev_monitor) {
- assert(udev_monitor);
-
- return device_monitor_disconnect(udev_monitor->monitor);
-}
-
static struct udev_monitor *udev_monitor_free(struct udev_monitor *udev_monitor) {
assert(udev_monitor);
return device_monitor_get_fd(udev_monitor->monitor);
}
-int udev_monitor_receive_sd_device(struct udev_monitor *udev_monitor, sd_device **ret) {
+static int udev_monitor_receive_sd_device(struct udev_monitor *udev_monitor, sd_device **ret) {
struct pollfd pfd;
int r;
assert_return(udev_monitor, NULL);
r = udev_monitor_receive_sd_device(udev_monitor, &device);
- if (r < 0) {
- errno = -r;
- return NULL;
- }
+ if (r < 0)
+ return_with_errno(NULL, r);
return udev_device_new(udev_monitor->udev, device);
}
-int udev_monitor_send_device(
- struct udev_monitor *udev_monitor,
- struct udev_monitor *destination,
- struct udev_device *udev_device) {
- assert(udev_monitor);
- assert(udev_device);
-
- return device_monitor_send_device(udev_monitor->monitor,
- destination ? destination->monitor : NULL,
- udev_device->device);
-}
-
/**
* udev_monitor_filter_add_match_subsystem_devtype:
* @udev_monitor: the monitor