core: Improve robustness of event handling
authorChris Dickens <christopher.a.dickens@gmail.com>
Wed, 1 Mar 2017 07:06:39 +0000 (23:06 -0800)
committerChris Dickens <christopher.a.dickens@gmail.com>
Wed, 1 Mar 2017 07:06:39 +0000 (23:06 -0800)
commitecc87bba6e38d781a8f89b47f17c904a90b91e9d
treeffbd2aa370c02ff01e0d98f8227721848266f07c
parentb08b1993a8b3850b818a861d6317ba0df8b090ab
core: Improve robustness of event handling

Prior to this commit, it was possible on Linux to poll a file descriptor
that was not valid for libusb. This could happen given the following
sequence of events:

  1) Application registers hotplug callback
  2) Application calls into libusb to handle events
  3) USB device is unplugged, triggering hotplug event
  4) Event handling thread calls registered hotplug callback
  5) Hotplug callback calls libusb_close(), which closes the fd
  6) Event handling code retries the poll() call before returning

At this point, the file descriptor that is being passed to poll() may be
invalid or worse may not belong to libusb at all.

This commit fixes this by removing the code that restarted the poll() call.
It was originally added to allow the processing of multiple hotplug messages
when these messages were delivered across a pipe, but with a linked list now
holding the hotplug messages this is no longer a concern. If any hotplug
messages are present on the list, they are all processed in one pass.

Closes #238

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/io.c
libusb/libusbi.h
libusb/version_nano.h