]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - backend/usb-darwin.c
Merge changes from CUPS 1.7svn-r10629.
[thirdparty/cups.git] / backend / usb-darwin.c
index 7f634328df284070f53a85230591a840ffcf0c60..5f303bec5147d9bfba35c0b822c88a6ee8a49124 100644 (file)
@@ -1,7 +1,7 @@
 /*
 * "$Id: usb-darwin.c 7953 2008-09-17 01:43:19Z mike $"
 *
-* Copyright 2005-2011 Apple Inc. All rights reserved.
+* Copyright 2005-2012 Apple Inc. All rights reserved.
 *
 * IMPORTANT:  This Apple software is supplied to you by Apple Computer,
 * Inc. ("Apple") in consideration of your agreement to the following
@@ -684,7 +684,7 @@ print_device(const char *uri,               /* I - Device URI */
 
        /*
        * Ignore timeout errors, but retain the number of bytes written to
-       * avoid sending duplicate data (<rdar://problem/6254911>)...
+       * avoid sending duplicate data...
        */
 
        if (iostatus == kIOUSBTransactionTimeout)
@@ -707,7 +707,7 @@ print_device(const char *uri,               /* I - Device URI */
 
        /*
        * Retry a write after an aborted write since we probably just got
-       * SIGTERM (<rdar://problem/6860126>)...
+       * SIGTERM...
        */
 
        else if (iostatus == kIOReturnAborted)
@@ -761,24 +761,8 @@ print_device(const char *uri,              /* I - Device URI */
 
   fprintf(stderr, "DEBUG: Sent %lld bytes...\n", (off_t)total_bytes);
 
-  if (!print_fd)
-  {
-   /*
-    * Re-enable the SIGTERM handler so pthread_kill() will work...
-    */
-
-    struct sigaction   action;         /* POSIX signal action */
-
-    memset(&action, 0, sizeof(action));
-
-    sigemptyset(&action.sa_mask);
-    sigaddset(&action.sa_mask, SIGTERM);
-    action.sa_handler = sigterm_handler;
-    sigaction(SIGTERM, &action, NULL);
-  }
-
  /*
-  * Wait for the side channel thread to exit...
+  * Signal the side channel thread to exit...
   */
 
   if (have_sidechannel)
@@ -805,44 +789,23 @@ print_device(const char *uri,             /* I - Device URI */
                                   &cond_timeout) != 0)
          break;
       }
-
-      if (!g.sidechannel_thread_done)
-      {
-       /*
-       * Force the side-channel thread to exit...
-       */
-
-       fputs("DEBUG: Force the side-channel thread to exit...\n", stderr);
-       pthread_kill(sidechannel_thread_id, SIGTERM);
-      }
     }
 
     pthread_mutex_unlock(&g.sidechannel_thread_mutex);
-
-    pthread_join(sidechannel_thread_id, NULL);
-
-    pthread_cond_destroy(&g.sidechannel_thread_cond);
-    pthread_mutex_destroy(&g.sidechannel_thread_mutex);
   }
 
-  pthread_cond_destroy(&g.readwrite_lock_cond);
-  pthread_mutex_destroy(&g.readwrite_lock_mutex);
-
  /*
-  * Signal the read thread to stop...
+  * Signal the read thread to exit then wait 7 seconds for it to complete...
   */
 
   g.read_thread_stop = 1;
 
- /*
-  * Give the read thread WAIT_EOF_DELAY seconds to complete all the data. If
-  * we are not signaled in that time then force the thread to exit.
-  */
-
   pthread_mutex_lock(&g.read_thread_mutex);
 
   if (!g.read_thread_done)
   {
+    fputs("DEBUG: Waiting for read thread to exit...\n", stderr);
+
     gettimeofday(&tv, NULL);
     cond_timeout.tv_sec  = tv.tv_sec + WAIT_EOF_DELAY;
     cond_timeout.tv_nsec = tv.tv_usec * 1000;
@@ -854,25 +817,34 @@ print_device(const char *uri,             /* I - Device URI */
        break;
     }
 
+   /*
+    * If it didn't exit abort the pending read and wait an additional second...
+    */
+
     if (!g.read_thread_done)
     {
-     /*
-      * Force the read thread to exit...
-      */
+      fputs("DEBUG: Read thread still active, aborting the pending read...\n",
+           stderr);
 
       g.wait_eof = 0;
-      fputs("DEBUG: Force the read thread to exit...\n", stderr);
-      pthread_kill(read_thread_id, SIGTERM);
+
+      (*g.classdriver)->Abort(g.classdriver);
+
+      gettimeofday(&tv, NULL);
+      cond_timeout.tv_sec  = tv.tv_sec + 1;
+      cond_timeout.tv_nsec = tv.tv_usec * 1000;
+
+      while (!g.read_thread_done)
+      {
+       if (pthread_cond_timedwait(&g.read_thread_cond, &g.read_thread_mutex,
+                                  &cond_timeout) != 0)
+         break;
+      }
     }
   }
 
   pthread_mutex_unlock(&g.read_thread_mutex);
 
-  pthread_join(read_thread_id, NULL);  /* wait for the read thread to return */
-
-  pthread_cond_destroy(&g.read_thread_cond);
-  pthread_mutex_destroy(&g.read_thread_mutex);
-
  /*
   * Close the connection and input file and general clean up...
   */
@@ -1208,12 +1180,12 @@ static Boolean list_device_cb(void *refcon,
       if (!make ||
           !CFStringGetCString(make, makestr, sizeof(makestr),
                              kCFStringEncodingUTF8))
-        strcpy(makestr, "Unknown");
+        strlcpy(makestr, "Unknown", sizeof(makestr));
 
       if (!model ||
           !CFStringGetCString(model, &modelstr[1], sizeof(modelstr)-1,
                              kCFStringEncodingUTF8))
-        strcpy(modelstr + 1, "Printer");
+        strlcpy(modelstr + 1, "Printer", sizeof(modelstr) - 1);
 
       optionsstr[0] = '\0';
       if (serial != NULL)
@@ -1311,7 +1283,7 @@ static Boolean find_device_cb(void *refcon,
   if (!keepLooking && g.status_timer != NULL)
   {
     fputs("STATE: -offline-report\n", stderr);
-    _cupsLangPrintFilter(stderr, "INFO", _("Printer is now online."));
+    _cupsLangPrintFilter(stderr, "INFO", _("The printer is now online."));
     CFRunLoopRemoveTimer(CFRunLoopGetCurrent(), g.status_timer, kCFRunLoopDefaultMode);
     CFRelease(g.status_timer);
     g.status_timer = NULL;
@@ -1332,7 +1304,7 @@ static void status_timer_cb(CFRunLoopTimerRef timer,
   (void)info;
 
   fputs("STATE: +offline-report\n", stderr);
-  _cupsLangPrintFilter(stderr, "INFO", _("Printer is offline."));
+  _cupsLangPrintFilter(stderr, "INFO", _("The printer is offline."));
 
   if (getenv("CLASS") != NULL)
   {
@@ -1859,24 +1831,24 @@ static void parse_options(char *options,
     * Process the option...
     */
 
-    if (!strcasecmp(name, "waiteof"))
+    if (!_cups_strcasecmp(name, "waiteof"))
     {
-      if (!strcasecmp(value, "on") ||
-         !strcasecmp(value, "yes") ||
-         !strcasecmp(value, "true"))
+      if (!_cups_strcasecmp(value, "on") ||
+         !_cups_strcasecmp(value, "yes") ||
+         !_cups_strcasecmp(value, "true"))
        *wait_eof = true;
-      else if (!strcasecmp(value, "off") ||
-              !strcasecmp(value, "no") ||
-              !strcasecmp(value, "false"))
+      else if (!_cups_strcasecmp(value, "off") ||
+              !_cups_strcasecmp(value, "no") ||
+              !_cups_strcasecmp(value, "false"))
        *wait_eof = false;
       else
        _cupsLangPrintFilter(stderr, "WARNING",
                             _("Boolean expected for waiteof option \"%s\"."),
                             value);
     }
-    else if (!strcasecmp(name, "serial"))
+    else if (!_cups_strcasecmp(name, "serial"))
       strlcpy(serial, value, serial_size);
-    else if (!strcasecmp(name, "location") && location)
+    else if (!_cups_strcasecmp(name, "location") && location)
       *location = strtol(value, NULL, 16);
   }
 }
@@ -2175,9 +2147,9 @@ static void parse_pserror(char *sockBuffer,
       pCommentEnd += 3;            /* Skip past "]%%" */
       *pCommentEnd = '\0';         /* There's always room for the nul */
 
-      if (strncasecmp(pCommentBegin, "%%[ Error:", 10) == 0)
+      if (_cups_strncasecmp(pCommentBegin, "%%[ Error:", 10) == 0)
        logLevel = "DEBUG";
-      else if (strncasecmp(pCommentBegin, "%%[ Flushing", 12) == 0)
+      else if (_cups_strncasecmp(pCommentBegin, "%%[ Flushing", 12) == 0)
        logLevel = "DEBUG";
       else
        logLevel = "INFO";
@@ -2192,7 +2164,7 @@ static void parse_pserror(char *sockBuffer,
     }
 
     /* move everything over... */
-    strcpy(gErrorBuffer, pLineEnd);
+    strlcpy(gErrorBuffer, pLineEnd, sizeof(gErrorBuffer));
     gErrorBufferPtr = gErrorBuffer;
     pLineEnd = (char *)next_line((const char *)gErrorBuffer);
   }