laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/27038 )
Change subject: osmo_libusb: Use libusb_get_pollfds() to get initial file descriptors ...................................................................... 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 --- M src/usb/osmo_libusb.c 1 file changed, 13 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/38/27038/1 diff --git a/src/usb/osmo_libusb.c b/src/usb/osmo_libusb.c index a6f194a..79a8fc3 100644 --- a/src/usb/osmo_libusb.c +++ b/src/usb/osmo_libusb.c @@ -735,6 +735,8 @@ 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 @@ 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; } -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/27038 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: Icf81014d689ffa738719af68120fa2dedbeec689 Gerrit-Change-Number: 27038 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <lafo...@osmocom.org> Gerrit-MessageType: newchange