}
-static void
-udevEventHandleCallback(int watch ATTRIBUTE_UNUSED,
- int fd,
- int events ATTRIBUTE_UNUSED,
- void *data ATTRIBUTE_UNUSED)
+static bool
+udevEventMonitorSanityCheck(struct udev_monitor *udev_monitor,
+ int fd)
{
- struct udev_device *device = NULL;
- struct udev_monitor *udev_monitor = DRV_STATE_UDEV_MONITOR(driver);
- int udev_fd = -1;
+ int rc = -1;
- udev_fd = udev_monitor_get_fd(udev_monitor);
- if (fd != udev_fd) {
+ rc = udev_monitor_get_fd(udev_monitor);
+ if (fd != rc) {
udevPrivate *priv = driver->privateData;
virReportError(VIR_ERR_INTERNAL_ERROR,
_("File descriptor returned by udev %d does not "
"match node device file descriptor %d"),
- fd, udev_fd);
+ fd, rc);
/* this is a non-recoverable error, let's remove the handle, so that we
* don't get in here again because of some spurious behaviour and report
virEventRemoveHandle(priv->watch);
priv->watch = -1;
- goto cleanup;
+ return false;
}
+ return true;
+}
+
+
+static void
+udevEventHandleCallback(int watch ATTRIBUTE_UNUSED,
+ int fd,
+ int events ATTRIBUTE_UNUSED,
+ void *data ATTRIBUTE_UNUSED)
+{
+ struct udev_device *device = NULL;
+ struct udev_monitor *udev_monitor = NULL;
+
+ udev_monitor = DRV_STATE_UDEV_MONITOR(driver);
+
+ if (!udevEventMonitorSanityCheck(udev_monitor, fd))
+ return;
+
device = udev_monitor_receive_device(udev_monitor);
if (device == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("udev_monitor_receive_device returned NULL"));
- goto cleanup;
+ return;
}
udevHandleOneDevice(device);
-
- cleanup:
udev_device_unref(device);
- return;
}