From 980794795d867f3c7393870891d6301eac10f8f6 Mon Sep 17 00:00:00 2001
From: Chris Dickens <christopher.a.dickens@gmail.com>
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.
---
 libusb/os/linux_udev.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libusb/os/linux_udev.c b/libusb/os/linux_udev.c
index 4a45c4b..00694ab 100644
--- a/libusb/os/linux_udev.c
+++ b/libusb/os/linux_udev.c
@@ -82,6 +82,14 @@ 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_SETFD, O_NONBLOCK);
+	if (r) {
+		usbi_err(NULL, "could not set udev monitor fd to nonblock: %d", errno);
+		goto err_free_monitor;
+	}
+
 	r = pthread_create(&linux_event_thread, NULL, linux_udev_event_thread_main, NULL);
 	if (r) {
 		usbi_err(NULL, "could not create linux hotplug event thread");
-- 
1.8.1.1

