aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2022-01-31 18:37:36 +0100
committerHarald Welte <laforge@osmocom.org>2022-01-31 18:40:03 +0100
commita366a895976ffc17c632781f0c9e33a590ed94a7 (patch)
tree5a1a4bc40c3730c72d2341ff5bd62c9e1f0d6379
parentb12dbf76c254130f501fe546dc57732d51237048 (diff)
osmo_libusb: Use libusb_get_pollfds() to get initial file descriptors
It seems it is insufficient to register file-descriptor call-backs with libusb_set_pollfd_notifiers(), but we also need to call libusb_get_pollfds() once to get the initial set of file descriptors which may have been created already during libusb_init(). As we don't have a libusb context before libusb_init() returns, we cannot call libusb_set_pollfd_notifiers() early enough to be active already during libusb_init(). Change-Id: Icf81014d689ffa738719af68120fa2dedbeec689
-rw-r--r--src/usb/osmo_libusb.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/usb/osmo_libusb.c b/src/usb/osmo_libusb.c
index a6f194ad..79a8fc3b 100644
--- a/src/usb/osmo_libusb.c
+++ b/src/usb/osmo_libusb.c
@@ -735,6 +735,8 @@ int osmo_libusb_get_ep_addrs(libusb_device_handle *devh, unsigned int if_num,
int osmo_libusb_init(libusb_context **pluctx)
{
libusb_context *luctx = NULL;
+ const struct libusb_pollfd **pfds;
+
int rc;
rc = libusb_init(pluctx);
@@ -750,6 +752,17 @@ int osmo_libusb_init(libusb_context **pluctx)
libusb_set_pollfd_notifiers(luctx, osmo_usb_added_cb, osmo_usb_removed_cb, luctx);
+ /* get the initial file descriptors which were created even before during libusb_init() */
+ pfds = libusb_get_pollfds(luctx);
+ if (pfds) {
+ const struct libusb_pollfd **pfds2 = pfds;
+ const struct libusb_pollfd *pfd;
+ /* synthesize 'add' call-backs. not sure why libusb doesn't do that by itself? */
+ for (pfd = *pfds2; pfd; pfd = *++pfds2)
+ osmo_usb_added_cb(pfd->fd, pfd->events, luctx);
+ libusb_free_pollfds(pfds);
+ }
+
return 0;
}