diff options
author | Chris Dickens <christopher.a.dickens@gmail.com> | 2013-06-13 10:59:11 -0700 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2013-06-14 09:48:40 +0200 |
commit | 4d099d08a99aff38c72e393d7eef94b6436d39f8 (patch) | |
tree | a45ff1eb642fa86244e39c8aa4305ea01144f783 /libusb/os/linux_udev.c | |
parent | 41091f7a6ba7b0243f064b1999f7b4af84f6c3cf (diff) | |
download | libusb-4d099d08a99aff38c72e393d7eef94b6436d39f8.tar.gz |
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 <hdegoede@redhat.com>
Diffstat (limited to 'libusb/os/linux_udev.c')
-rw-r--r-- | libusb/os/linux_udev.c | 13 |
1 files changed, 13 insertions, 0 deletions
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); |