hotplug: ensure udev monitor fd is non-blocking
authorChris Dickens <christopher.a.dickens@gmail.com>
Thu, 13 Jun 2013 17:59:11 +0000 (10:59 -0700)
committerHans de Goede <hdegoede@redhat.com>
Fri, 14 Jun 2013 07:48:40 +0000 (09:48 +0200)
Some older versions of udev do not automatically set the udev
monitor fd to non-blocking mode. This patch ensures that this is
always set.

HdG: Get flags then or in O_NONBLOCK and set them, rather then setting flags
to only O_NONBLOCK.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
libusb/os/linux_udev.c
libusb/version_nano.h

index 27ee7ed..29c949a 100644 (file)
@@ -82,6 +82,19 @@ int linux_udev_start_event_monitor(void)
 
        udev_monitor_fd = udev_monitor_get_fd(udev_monitor);
 
+       /* Some older versions of udev are not non-blocking by default,
+        * so make sure this is set */
+       r = fcntl(udev_monitor_fd, F_GETFL);
+       if (r == -1) {
+               usbi_err(NULL, "getting udev monitor fd flags (%d)", errno);
+               goto err_free_monitor;
+       }
+       r = fcntl(udev_monitor_fd, F_SETFL, r | O_NONBLOCK);
+       if (r) {
+               usbi_err(NULL, "setting udev monitor fd flags (%d)", errno);
+               goto err_free_monitor;
+       }
+
        r = pthread_create(&linux_event_thread, NULL, linux_udev_event_thread_main, NULL);
        if (r) {
                usbi_err(NULL, "creating hotplug event thread (%d)", r);
index f115614..5d7f2b9 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10735
+#define LIBUSB_NANO 10736