summaryrefslogtreecommitdiff
path: root/extra/cups/usb-backend-do-not-crash-if-usb-disabled-in-bios.patch
blob: 711dab8ce9e1fb9f75a10adc59f0219f64a56a1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Description: Add more error handling to the libusb-based USB backend,
 especially to avoid a crash when USB is disabled in the BIOS. Also
 discard that error when counting warning messages.
Author: Till Kamppeter <till.kamppeter@gmail.com>
Bug-Ubuntu: https://bugs.launchpad.net/bugs/1108719
Last-Update: 2013-05-03
--- a/backend/usb-libusb.c
+++ b/backend/usb-libusb.c
@@ -898,7 +898,8 @@
 					/* Pointer to current alternate setting */
   const struct libusb_endpoint_descriptor *endpptr = NULL;
 					/* Pointer to current endpoint */
-  ssize_t               numdevs,        /* number of connected devices */
+  ssize_t               err = 0,
+                        numdevs,        /* number of connected devices */
                         i = 0;
   uint8_t		conf,		/* Current configuration */
 			iface,		/* Current interface */
@@ -917,7 +918,13 @@
   * Initialize libusb...
   */
 
-  libusb_init(NULL);
+  err = libusb_init(NULL);
+  if (err)
+  {
+    fprintf(stderr, "WARNING: Unable to initialize USB access via libusb, libusb error %i\n", err);
+    return (NULL);
+  }
+
   numdevs = libusb_get_device_list(NULL, &list);
   fprintf(stderr, "DEBUG: libusb_get_device_list=%d\n", (int)numdevs);
 
@@ -1087,7 +1094,8 @@
   * Clean up ....
   */
 
-  libusb_free_device_list(list, 1);
+  if (numdevs >= 0)
+    libusb_free_device_list(list, 1);
   libusb_exit(NULL);
 
   return (NULL);
--- a/test/run-stp-tests.sh
+++ b/test/run-stp-tests.sh
@@ -838,7 +838,7 @@
 fi
 
 # Warning log messages
-count=`$GREP '^W ' /tmp/cups-$user/log/error_log | wc -l | awk '{print $1}'`
+count=`$GREP '^W ' /tmp/cups-$user/log/error_log | grep -v 'Unable to initialize USB access via libusb, libusb error' | wc -l | awk '{print $1}'`
 if test $count != 9; then
 	echo "FAIL: $count warning messages, expected 9."
 	$GREP '^W ' /tmp/cups-$user/log/error_log