summaryrefslogtreecommitdiffstats
path: root/usb-linux.c
diff options
context:
space:
mode:
authorGravatar Hector Martin2009-05-05 00:37:19 +0200
committerGravatar Hector Martin2009-05-05 00:37:19 +0200
commit9bf93e406de3a06cee0a1452bf1da3c6f697ee31 (patch)
tree748061dd3eef7c8f76212c6cbade2249432bd7a4 /usb-linux.c
parentbcf6842e29b6cdaf71a8043fb0a0e42c032f1ed6 (diff)
downloadusbmuxd-9bf93e406de3a06cee0a1452bf1da3c6f697ee31.tar.gz
usbmuxd-9bf93e406de3a06cee0a1452bf1da3c6f697ee31.tar.bz2
Make usb die only after several repeated failures to get device list
(libusb problem?)
Diffstat (limited to 'usb-linux.c')
-rw-r--r--usb-linux.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/usb-linux.c b/usb-linux.c
index 3a87ba6..b401cde 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -51,6 +51,8 @@ static struct collection device_list;
static struct timeval next_dev_poll_time;
+static int devlist_failures;
+
static void usb_disconnect(struct usb_device *dev)
{
if(!dev->dev) {
@@ -219,9 +221,21 @@ static int usb_discover(void)
cnt = libusb_get_device_list(NULL, &devs);
if(cnt < 0) {
- usbmuxd_log(LL_FATAL, "Could not get device list: %d", cnt);
- return cnt;
+ usbmuxd_log(LL_WARNING, "Could not get device list: %d", cnt);
+ devlist_failures++;
+ // sometimes libusb fails getting the device list if you've just removed something
+ if(devlist_failures > 5) {
+ usbmuxd_log(LL_FATAL, "Too many errors getting device list\n");
+ return cnt;
+ } else {
+ gettimeofday(&next_dev_poll_time, NULL);
+ next_dev_poll_time.tv_usec += DEVICE_POLL_TIME * 1000;
+ next_dev_poll_time.tv_sec += next_dev_poll_time.tv_usec / 1000000;
+ next_dev_poll_time.tv_usec = next_dev_poll_time.tv_usec % 1000000;
+ return 0;
+ }
}
+ devlist_failures = 0;
usbmuxd_log(LL_SPEW, "usb_discover: scanning %d devices", cnt);
@@ -462,6 +476,7 @@ int usb_init(void)
int res;
usbmuxd_log(LL_DEBUG, "usb_init for linux / libusb 1.0");
+ devlist_failures = 0;
res = libusb_init(NULL);
//libusb_set_debug(NULL, 3);
if(res != 0) {