/*
* "$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
/*
* 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)
/*
* Retry a write after an aborted write since we probably just got
- * SIGTERM (<rdar://problem/6860126>)...
+ * SIGTERM...
*/
else if (iostatus == kIOReturnAborted)
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)
&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;
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...
*/
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)
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;
(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)
{
* 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);
}
}
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";
}
/* move everything over... */
- strcpy(gErrorBuffer, pLineEnd);
+ strlcpy(gErrorBuffer, pLineEnd, sizeof(gErrorBuffer));
gErrorBufferPtr = gErrorBuffer;
pLineEnd = (char *)next_line((const char *)gErrorBuffer);
}