From 4d099d08a99aff38c72e393d7eef94b6436d39f8 Mon Sep 17 00:00:00 2001 From: Chris Dickens Date: Thu, 13 Jun 2013 10:59:11 -0700 Subject: [PATCH] hotplug: ensure udev monitor fd is non-blocking 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 --- libusb/os/linux_udev.c | 13 +++++++++++++ libusb/version_nano.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libusb/os/linux_udev.c b/libusb/os/linux_udev.c index 27ee7ed..29c949a 100644 --- a/libusb/os/linux_udev.c +++ b/libusb/os/linux_udev.c @@ -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); diff --git a/libusb/version_nano.h b/libusb/version_nano.h index f115614..5d7f2b9 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 10735 +#define LIBUSB_NANO 10736 -- 2.7.4