~ubuntu-branches/ubuntu/quantal/cups/quantal-updates

« back to all changes in this revision

Viewing changes to debian/patches/usb-backend-further-enhancements.patch

  • Committer: Package Import Robot
  • Author(s): Martin Pitt, Till Kamppeter, Martin Pitt
  • Date: 2012-07-11 08:57:53 UTC
  • mfrom: (100.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20120711085753-5ls8k6pem3xf91te
Tags: 1.5.3-4
[ Till Kamppeter ]
* debian/patches/usb-backend-further-enhancements.patch: USB backend: Do
  a printer reset after each job, this makes the Prolific USB -> Parallel
  adapter finally work (LP: #987485) and makes it unnecessary to blacklist
  the usblp kernel module for some printers (LP: #997040).

[ Martin Pitt ]
* debian/control: Have cups strictly depend on the same binary version of
  libcups2, to avoid crashes when later libcups2 versions remove private
  symbols. (Closes: #668662)
* Add snmp-dont-stop-without-ipv6.patch: snmp: do not die if there is no
  IPv6 support available. Patch backported from upstream trunk, thanks to
  Pino Toscano! (first half of #680604)
* tests-ignore-warnings.patch: Also ignore avahi failure -1, to fix FTBFS on
  hurd due to D-BUS problems. Thanks Pino Toscano! (Closes: #680604)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
  *   read_thread()       - Thread to read the backchannel data on.
20
20
  *   sidechannel_thread() - Handle side-channel requests.
21
21
  *   soft_reset()        - Send a soft reset to the device.
22
 
@@ -60,13 +63,14 @@
 
22
@@ -60,13 +63,15 @@
23
23
 {
24
24
   struct libusb_device *device;        /* Device info */
25
25
   int                  conf,           /* Configuration */
32
32
                        protocol,       /* Protocol: 1 = Uni-di, 2 = Bi-di. */
33
33
-                        usblp_attached; /* Is the "usblp" kernel module
34
34
-                                          attached? */
35
 
+                       usblp_attached; /* "usblp" kernel module attached? */
 
35
+                       usblp_attached, /* "usblp" kernel module attached? */
 
36
+                       opened_for_job; /* Set to 1 by print_device() */
36
37
+  unsigned int         quirks;         /* Quirks flags */
37
38
   struct libusb_device_handle *handle; /* Open handle to device */
38
39
 } usb_printer_t;
39
40
 
40
 
@@ -99,6 +103,55 @@
 
41
@@ -99,6 +104,55 @@
41
42
   int                  sidechannel_thread_done;
42
43
 } usb_globals_t;
43
44
 
93
94
 
94
95
 /*
95
96
  * Globals...
96
 
@@ -124,6 +177,8 @@
 
97
@@ -124,6 +178,8 @@
97
98
 static int             open_device(usb_printer_t *printer, int verbose);
98
99
 static int             print_cb(usb_printer_t *printer, const char *device_uri,
99
100
                                 const char *device_id, const void *data);
102
103
 static void            *read_thread(void *reference);
103
104
 static void            *sidechannel_thread(void *reference);
104
105
 static void            soft_reset(void);
105
 
@@ -163,7 +218,8 @@
 
106
@@ -163,7 +219,8 @@
106
107
                iostatus;               /* Current IO status */
107
108
   pthread_t    read_thread_id,         /* Read thread */
108
109
                sidechannel_thread_id;  /* Side-channel thread */
112
113
   struct stat   sidechannel_info;      /* Side-channel file descriptor info */
113
114
   unsigned char        print_buffer[8192],     /* Print data buffer */
114
115
                *print_ptr;             /* Pointer into print data buffer */
115
 
@@ -172,6 +228,9 @@
 
116
@@ -172,6 +229,9 @@
116
117
   struct timeval *timeout,             /* Timeout pointer */
117
118
                tv;                     /* Time value */
118
119
   struct timespec cond_timeout;                /* pthread condition timeout */
122
123
 
123
124
 
124
125
  /*
125
 
@@ -187,6 +246,7 @@
 
126
@@ -187,6 +247,7 @@
126
127
   * Connect to the printer...
127
128
   */
128
129
 
130
131
   while ((g.printer = find_device(print_cb, uri)) == NULL)
131
132
   {
132
133
     _cupsLangPrintFilter(stderr, "INFO",
133
 
@@ -240,26 +300,63 @@
 
134
@@ -195,6 +256,7 @@
 
135
   }
 
136
 
 
137
   g.print_fd = print_fd;
 
138
+  g.printer->opened_for_job = 1;
 
139
 
 
140
  /*
 
141
   * If we are printing data from a print driver on stdin, ignore SIGTERM
 
142
@@ -240,24 +302,61 @@
134
143
   }
135
144
 
136
145
  /*
137
146
-  * Get the read thread going...
138
147
+  * Debug mode: If option "usb-unidir" is given, always deactivate
139
148
+  * backchannel
140
 
   */
141
 
 
142
 
-  g.read_thread_stop = 0;
143
 
-  g.read_thread_done = 0;
 
149
+  */
 
150
+
144
151
+  num_opts = cupsParseOptions(argv[5], 0, &opts);
145
152
+  val = cupsGetOption("usb-unidir", num_opts, opts);
146
153
+  if (val && strcasecmp(val, "no") && strcasecmp(val, "off") &&
150
157
+    fprintf(stderr, "DEBUG: Forced uni-directional communication "
151
158
+           "via \"usb-unidir\" option.\n");
152
159
+  }
 
160
+
 
161
+ /*
 
162
+  * Debug mode: If option "usb-no-reattach" is given, do not re-attach
 
163
+  * the usblp kernel module after the job has completed.
 
164
   */
 
165
 
 
166
-  g.read_thread_stop = 0;
 
167
-  g.read_thread_done = 0;
 
168
+  val = cupsGetOption("usb-no-reattach", num_opts, opts);
 
169
+  if (val && strcasecmp(val, "no") && strcasecmp(val, "off") &&
 
170
+      strcasecmp(val, "false"))
 
171
+  {
 
172
+    g.printer->usblp_attached = 0;
 
173
+    fprintf(stderr, "DEBUG: Forced not re-attaching the usblp kernel module "
 
174
+           "after the job via \"usb-no-reattach\" option.\n");
 
175
+  }
153
176
 
154
177
-  pthread_cond_init(&g.read_thread_cond, NULL);
155
178
-  pthread_mutex_init(&g.read_thread_mutex, NULL);
156
179
+ /*
157
 
+  * Debug mode: If option "usb-no-reattach" is given, do not re-attach
158
 
+  * the usblp kernel module after the job has completed.
 
180
+  * Get the read thread going...
159
181
+  */
160
182
 
161
183
-  if (pthread_create(&read_thread_id, NULL, read_thread, NULL))
162
 
+  val = cupsGetOption("usb-no-reattach", num_opts, opts);
163
 
+  if (val && strcasecmp(val, "no") && strcasecmp(val, "off") &&
164
 
+      strcasecmp(val, "false"))
 
184
+  if (g.printer->read_endp != -1)
165
185
   {
166
186
-    fprintf(stderr, "DEBUG: Fatal USB error.\n");
167
187
-    _cupsLangPrintFilter(stderr, "ERROR",
169
189
-    fputs("DEBUG: Couldn't create read thread.\n", stderr);
170
190
-    close_device(g.printer);
171
191
-    return (CUPS_BACKEND_STOP);
172
 
+    g.printer->usblp_attached = 0;
173
 
+    fprintf(stderr, "DEBUG: Forced not re-attaching the usblp kernel module "
174
 
+           "after the job via \"usb-no-reattach\" option.\n");
175
 
   }
176
 
 
177
 
  /*
178
 
+  * Get the read thread going...
179
 
+  */
180
 
+
181
 
+  if (g.printer->read_endp != -1)
182
 
+  {
183
192
+    have_backchannel = 1;
184
193
+
185
194
+    g.read_thread_stop = 0;
197
206
+      close_device(g.printer);
198
207
+      return (CUPS_BACKEND_STOP);
199
208
+    }
200
 
+  }
 
209
   }
201
210
+  else
202
211
+    fprintf(stderr, "DEBUG: Uni-directional device/mode, back channel "
203
212
+           "deactivated.\n");
204
 
+
205
 
+ /*
 
213
 
 
214
  /*
206
215
   * The main thread sends the print file...
207
 
   */
208
 
 
209
 
@@ -515,50 +612,54 @@
 
216
@@ -515,50 +614,54 @@
210
217
   * Signal the read thread to exit then wait 7 seconds for it to complete...
211
218
   */
212
219
 
223
230
-    gettimeofday(&tv, NULL);
224
231
-    cond_timeout.tv_sec  = tv.tv_sec + WAIT_EOF_DELAY;
225
232
-    cond_timeout.tv_nsec = tv.tv_usec * 1000;
226
 
+    pthread_mutex_lock(&g.read_thread_mutex);
227
 
 
 
233
-
228
234
-    while (!g.read_thread_done)
229
235
-    {
230
236
-      if (pthread_cond_timedwait(&g.read_thread_cond, &g.read_thread_mutex,
231
237
-                                &cond_timeout) != 0)
232
238
-       break;
233
239
-    }
234
 
-
 
240
+    pthread_mutex_lock(&g.read_thread_mutex);
 
241
 
235
242
-   /*
236
243
-    * If it didn't exit abort the pending read and wait an additional second...
237
244
-    */
289
296
 
290
297
   if (print_fd)
291
298
     close(print_fd);
292
 
@@ -601,24 +702,54 @@
 
299
@@ -601,24 +704,54 @@
293
300
     */
294
301
 
295
302
     int errcode;                       /* Return value of libusb function */
352
359
        {
353
360
          errcode = libusb_get_device_descriptor (printer->device, &devdesc);
354
361
          if (errcode < 0)
355
 
@@ -629,9 +760,11 @@
 
362
@@ -629,8 +762,25 @@
356
363
                    "DEBUG: Failed to re-attach \"usblp\" kernel module to "
357
364
                    "%04x:%04x\n", devdesc.idVendor, devdesc.idProduct);
358
365
        }
359
 
-
360
 
-      libusb_free_config_descriptor(confptr);
361
 
     }
 
366
+    }
362
367
+    else
363
368
+      fprintf(stderr,
364
369
+             "DEBUG: Failed to get configuration descriptor %d\n",
365
370
+             printer->conf);
366
371
 
 
372
-      libusb_free_config_descriptor(confptr);
 
373
+   /*
 
374
+    * Reset the device to clean up after the job
 
375
+    */
 
376
+
 
377
+    if (printer->opened_for_job == 1)
 
378
+    {
 
379
+      if ((errcode = libusb_reset_device(printer->handle)) < 0)
 
380
+       fprintf(stderr,
 
381
+               "DEBUG: Device reset failed, error code: %d\n",
 
382
+               errcode);
 
383
+      else
 
384
+       fprintf(stderr,
 
385
+               "DEBUG: Resetting printer.\n");
 
386
     }
 
387
 
367
388
    /*
368
 
     * Close the interface and return...
369
 
@@ -702,16 +835,18 @@
 
389
@@ -702,16 +852,18 @@
370
390
       * a printer...
371
391
       */
372
392
 
387
407
          continue;
388
408
         for (iface = 0, ifaceptr = confptr->interface;
389
409
             iface < confptr->bNumInterfaces;
390
 
@@ -733,13 +868,18 @@
 
410
@@ -733,13 +885,18 @@
391
411
            * 1284.4 (packet mode) protocol as well.
392
412
            */
393
413
 
408
428
            read_endp  = -1;
409
429
            write_endp = -1;
410
430
 
411
 
@@ -764,7 +904,10 @@
 
431
@@ -764,7 +921,10 @@
412
432
               protocol           = altptr->bInterfaceProtocol;
413
433
              printer.altset     = altset;
414
434
              printer.write_endp = write_endp;
420
440
            }
421
441
          }
422
442
 
423
 
@@ -782,16 +925,41 @@
 
443
@@ -782,16 +942,41 @@
424
444
              make_device_uri(&printer, device_id, device_uri,
425
445
                              sizeof(device_uri));
426
446
 
466
486
                return (&printer);
467
487
               }
468
488
 
469
 
@@ -959,7 +1127,7 @@
 
489
@@ -959,7 +1144,7 @@
470
490
   if ((sern = cupsGetOption("SERIALNUMBER", num_values, values)) == NULL)
471
491
     if ((sern = cupsGetOption("SERN", num_values, values)) == NULL)
472
492
       if ((sern = cupsGetOption("SN", num_values, values)) == NULL &&
475
495
           devdesc.iSerialNumber))
476
496
       {
477
497
        /*
478
 
@@ -1095,15 +1263,19 @@
 
498
@@ -1095,15 +1280,20 @@
479
499
   * Try opening the printer...
480
500
   */
481
501
 
488
508
+  }
489
509
 
490
510
   printer->usblp_attached = 0;
 
511
+  printer->opened_for_job = 0;
491
512
 
492
513
   if (verbose)
493
514
     fputs("STATE: +connecting-to-device\n", stderr);
497
518
   {
498
519
     fprintf(stderr, "DEBUG: Failed to get device descriptor, code: %d\n",
499
520
            errcode);
500
 
@@ -1151,6 +1323,8 @@
 
521
@@ -1151,6 +1341,8 @@
501
522
                0, 0, (unsigned char *)&current, 1, 5000) < 0)
502
523
     current = 0;                       /* Assume not configured */
503
524
 
506
527
   if ((errcode = 
507
528
        libusb_get_config_descriptor (printer->device, printer->conf, &confptr))
508
529
       < 0)
509
 
@@ -1163,6 +1337,8 @@
 
530
@@ -1163,6 +1355,8 @@
510
531
 
511
532
   if (number1 != current)
512
533
   {
515
536
     if ((errcode = libusb_set_configuration(printer->handle, number1)) < 0)
516
537
     {
517
538
      /*
518
 
@@ -1342,6 +1518,64 @@
 
539
@@ -1342,6 +1536,64 @@
519
540
 
520
541
 
521
542
 /*
580
601
  * 'read_thread()' - Thread to read the backchannel data on.
581
602
  */
582
603
 
583
 
@@ -1615,7 +1849,7 @@
 
604
@@ -1615,7 +1867,7 @@
584
605
   * Send the reset...
585
606
   */
586
607