Sophie

Sophie

distrib > Fedora > 20 > x86_64 > by-pkgid > df72bba5c54c30e36d9cecabc95e37dd > files > 2

libticables2-1.3.4-3.fc20.src.rpm

diff -rupN libticables2-1.3.4/src/ticables.c libticables2-1.3.4_patched/src/ticables.c
--- libticables2-1.3.4/src/ticables.c	2013-03-29 08:48:00.000000000 -0400
+++ libticables2-1.3.4_patched/src/ticables.c	2015-04-06 15:29:22.929649741 -0400
@@ -92,6 +92,12 @@ static CableFncts const *const cables[]
 // not static, must be shared between instances
 int ticables_instance = 0;	// counts # of instances
 
+// Did initializing libusb_1.0 work? Keep track of that with a flag.
+// --Ben Rosser (TC01)
+#ifdef HAVE_LIBUSB_1_0
+	int libusb_working = -1;
+#endif
+
 /**
  * ticables_library_init:
  *
@@ -153,9 +159,11 @@ TIEXPORT1 int TICALL ticables_library_in
 	/* init the libusb */
 	usb_init();
 #elif defined(HAVE_LIBUSB_1_0)
-	/* init the libusb */
-	libusb_init(NULL);
-	libusb_set_debug(NULL, 3);
+	/* init the libusb, if it fails, keep track of that. */
+	libusb_working = libusb_init(NULL);
+	if (libusb_working == LIBUSB_SUCCESS) {
+		libusb_set_debug(NULL, 3);
+	}
 #endif
 
 	return (++ticables_instance);
@@ -175,7 +183,9 @@ TICALL ticables_library_exit(void)
 #if defined(HAVE_LIBUSB)
 	// No exit function for libusb 0.1.x.
 #elif defined(HAVE_LIBUSB_1_0)
-	libusb_exit(NULL); // XXX NULL ?
+	if (libusb_working == LIBUSB_SUCCESS) {
+		libusb_exit(NULL); // XXX NULL ?
+	}
 #endif
 	return (--ticables_instance);
 }