*
* Contents:
*
-* list_devices() - List all USB devices.
-* print_device() - Print a file to a USB device.
-* sidechannel_thread() - Thread to handle side-channel requests.
-* read_thread() - Thread to read the backchannel data on.
-* list_device_cb() - list_device iterator callback.
-* find_device_cb() - print_device iterator callback.
-* status_timer_cb() - Status timer callback.
-* iterate_printers() - Iterate over all the printers.
-* device_added() - Device added notifier.
-* copy_deviceinfo() - Copy strings from the 1284 device ID.
-* release_deviceinfo() - Release deviceinfo strings.
-* load_classdriver() - Load a classdriver.
-* unload_classdriver() - Unload a classdriver.
-* load_printerdriver() - Load vendor's classdriver.
-* registry_open() - Open a connection to the printer.
-* registry_close() - Close the connection to the printer.
-* copy_deviceid() - Copy the 1284 device id string.
-* copy_devicestring() - Copy the 1284 device id string.
-* copy_value_for_key() - Copy value string associated with a key.
-* cfstr_create_trim() - Create CFString and trim whitespace characters.
-* parse_options() - Parse uri options.
-* setup_cfLanguage() - Create AppleLanguages array from LANG environment var.
-* run_legacy_backend() - Re-exec backend as ppc or i386.
-* sigterm_handler() - SIGTERM handler.
-* next_line() - Find the next line in a buffer.
-* parse_pserror() - Scan the backchannel data for postscript errors.
-* get_device_id() - Return IEEE-1284 device ID.
+ * list_devices() - List all USB devices.
+ * print_device() - Print a file to a USB device.
+ * read_thread() - Thread to read the backchannel data on.
+ * sidechannel_thread() - Handle side-channel requests.
+ * iterate_printers() - Iterate over all the printers.
+ * device_added() - Device added notifier.
+ * list_device_cb() - list_device iterator callback.
+ * find_device_cb() - print_device iterator callback.
+ * status_timer_cb() - Status timer callback.
+ * copy_deviceinfo() - Copy strings from the 1284 device ID.
+ * release_deviceinfo() - Release deviceinfo strings.
+ * load_classdriver() - Load a classdriver.
+ * unload_classdriver() - Unload a classdriver.
+ * load_printerdriver() - Load vendor's classdriver.
+ * registry_open() - Open a connection to the printer.
+ * registry_close() - Close the connection to the printer.
+ * copy_deviceid() - Copy the 1284 device id string.
+ * copy_devicestring() - Copy the 1284 device id string.
+ * copy_value_for_key() - Copy value string associated with a key.
+ * cfstr_create_trim() - Create CFString and trim whitespace characters.
+ * parse_options() - Parse URI options.
+ * sigterm_handler() - SIGTERM handler.
+ * next_line() - Find the next line in a buffer.
+ * parse_pserror() - Scan the backchannel data for postscript errors.
+ * soft_reset() - Send a soft reset to the device.
+ * get_device_id() - Return IEEE-1284 device ID.
*/
/*
#if defined(__i386__) || defined(__x86_64__)
static pid_t child_pid; /* Child PID */
static void run_legacy_backend(int argc, char *argv[], int fd); /* Starts child backend process running as a ppc executable */
-static void sigterm_handler(int sig); /* SIGTERM handler */
#endif /* __i386__ || __x86_64__ */
+static void sigterm_handler(int sig); /* SIGTERM handler */
#ifdef PARSE_PS_ERRORS
static const char *next_line (const char *buffer);
if (!g.make || !g.model)
{
- _cupsLangPuts(stderr, _("ERROR: Fatal USB error\n"));
+ fprintf(stderr, "DEBUG: Fatal USB error.\n");
+ _cupsLangPrintFilter(stderr, "ERROR",
+ _("There was an unrecoverable USB error."));
if (!g.make)
fputs("DEBUG: USB make string is NULL\n", stderr);
strlcpy(print_buffer, "USB class driver", sizeof(print_buffer));
fputs("STATE: +apple-missing-usbclassdriver-error\n", stderr);
- _cupsLangPuts(stderr, _("ERROR: Fatal USB error\n"));
+ _cupsLangPrintFilter(stderr, "ERROR",
+ _("There was an unrecoverable USB error."));
fprintf(stderr, "DEBUG: Could not load %s\n", print_buffer);
if (driverBundlePath)
countdown -= PRINTER_POLLING_INTERVAL;
if (countdown <= 0)
{
- _cupsLangPuts(stderr,
- _("INFO: Waiting for printer to become available...\n"));
+ _cupsLangPrintFilter(stderr, "INFO",
+ _("Waiting for printer to become available."));
fprintf(stderr, "DEBUG: USB printer status: 0x%08x\n", (int)status);
countdown = SUBSEQUENT_LOG_INTERVAL; /* subsequent log entries, every 15 seconds */
}
if (pthread_create(&sidechannel_thread_id, NULL, sidechannel_thread, NULL))
{
- _cupsLangPuts(stderr, _("ERROR: Fatal USB error\n"));
+ fprintf(stderr, "DEBUG: Fatal USB error.\n");
+ _cupsLangPrintFilter(stderr, "ERROR",
+ _("There was an unrecoverable USB error."));
fputs("DEBUG: Couldn't create side-channel thread\n", stderr);
registry_close();
return (CUPS_BACKEND_STOP);
if (pthread_create(&read_thread_id, NULL, read_thread, NULL))
{
- _cupsLangPuts(stderr, _("ERROR: Fatal USB error\n"));
+ fprintf(stderr, "DEBUG: Fatal USB error.\n");
+ _cupsLangPrintFilter(stderr, "ERROR",
+ _("There was an unrecoverable USB error."));
fputs("DEBUG: Couldn't create read thread\n", stderr);
registry_close();
return (CUPS_BACKEND_STOP);
while (status == noErr && copies-- > 0)
{
- _cupsLangPuts(stderr, _("INFO: Sending print data...\n"));
+ _cupsLangPrintFilter(stderr, "INFO", _("Sending data to printer."));
if (print_fd != STDIN_FILENO)
{
}
else if (errno != EAGAIN && errno != EINTR)
{
- _cupsLangPuts(stderr, _("ERROR: Unable to read print data\n"));
+ _cupsLangPrintFilter(stderr, "ERROR",
+ _("Unable to read print data."));
perror("DEBUG: select");
registry_close();
return (CUPS_BACKEND_FAILED);
if (errno != EAGAIN && errno != EINTR)
{
- _cupsLangPuts(stderr, _("ERROR: Unable to read print data\n"));
+ _cupsLangPrintFilter(stderr, "ERROR",
+ _("Unable to read print data."));
perror("DEBUG: read");
registry_close();
return (CUPS_BACKEND_FAILED);
iostatus = (*g.classdriver)->WritePipe(g.classdriver, (UInt8*)print_ptr, &bytes, 0);
}
- if (iostatus || bytes < 0)
+ if (iostatus)
{
/*
* Write error - bail if we don't see an error we can retry...
*/
-
- _cupsLangPuts(stderr, _("ERROR: Unable to send print data\n"));
+ _cupsLangPrintFilter(stderr, "ERROR",
+ _("Unable to send data to printer."));
fprintf(stderr, "DEBUG: USB class driver WritePipe returned %x\n",
iostatus);
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...
*/
* Force the side-channel thread to exit...
*/
+ fputs("DEBUG: Force the side-channel thread to exit...\n", stderr);
pthread_kill(sidechannel_thread_id, SIGTERM);
}
}
*/
g.wait_eof = 0;
+ fputs("DEBUG: Force the read thread to exit...\n", stderr);
pthread_kill(read_thread_id, SIGTERM);
}
}
if (!keepLooking && g.status_timer != NULL)
{
fputs("STATE: -offline-report\n", stderr);
- _cupsLangPuts(stderr, _("INFO: Printer is now online.\n"));
+ _cupsLangPrintFilter(stderr, "INFO", _("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);
- _cupsLangPuts(stderr, _("INFO: Printer is offline.\n"));
+ _cupsLangPrintFilter(stderr, "INFO", _("Printer is offline."));
if (getenv("CLASS") != NULL)
{
if (stat(bundlestr, &bundleinfo))
{
- fprintf(stderr, "DEBUG: Unable to load class driver \"%s\": %s\n",
+ fprintf(stderr, "DEBUG: Class driver \"%s\" not available: %s\n",
bundlestr, strerror(errno));
- return (kr);
+ fputs("STATE: +cups-missing-filter-warning\n", stderr);
+
+ if (errno == ENOENT && driverPath)
+ return (load_classdriver(NULL, intf, printerDriver));
+ else
+ return (kr);
}
- else if (bundleinfo.st_mode & S_IWOTH)
+ else if (bundleinfo.st_uid ||
+ (bundleinfo.st_gid && (bundleinfo.st_mode & S_IWGRP)) ||
+ (bundleinfo.st_mode & S_IWOTH))
{
- fprintf(stderr, "DEBUG: Unable to load class driver \"%s\": insecure file "
- "permissions (0%o)\n", bundlestr, bundleinfo.st_mode);
- return (kr);
+ fprintf(stderr, "DEBUG: Class driver \"%s\" has insecure file "
+ "permissions (0%o/uid=%d/gid=%d).\n", bundlestr,
+ bundleinfo.st_mode, (int)bundleinfo.st_uid,
+ (int)bundleinfo.st_gid);
+ fputs("STATE: +cups-insecure-filter-warning\n", stderr);
+
+ if (bundleinfo.st_uid || (bundleinfo.st_mode & S_IWOTH))
+ {
+ if (driverPath)
+ return (load_classdriver(NULL, intf, printerDriver));
+ else
+ return (kr);
+ }
}
/*
!strcasecmp(value, "false"))
*wait_eof = false;
else
- _cupsLangPrintf(stderr,
- _("WARNING: Boolean expected for waiteof option "
- "\"%s\"\n"), value);
+ _cupsLangPrintFilter(stderr, "WARNING",
+ _("Boolean expected for waiteof option \"%s\"."),
+ value);
}
else if (!strcasecmp(name, "serial"))
strlcpy(serial, value, serial_size);
# else
perror("DEBUG: Unable to set binary preference to ppc");
# endif /* __x86_64__ */
- _cupsLangPrintf(stderr, _("Unable to use legacy USB class driver\n"));
+ _cupsLangPrintFilter(stderr, "ERROR",
+ _("Unable to use legacy USB class driver."));
exit(CUPS_BACKEND_STOP);
}
}
{
fprintf(stderr, "DEBUG: Unable to exec %s: %s\n", usbpath,
strerror(err));
- _cupsLangPrintf(stderr, _("Unable to use legacy USB class driver\n"));
+ _cupsLangPrintFilter(stderr, "ERROR",
+ _("Unable to use legacy USB class driver."));
exit(CUPS_BACKEND_STOP);
}
exit(exitstatus);
}
+#endif /* __i386__ || __x86_64__ */
+
/*
* 'sigterm_handler()' - SIGTERM handler.
static void
sigterm_handler(int sig) /* I - Signal */
{
- /* If we started a child process pass the signal on to it...
- */
+#if defined(__i386__) || defined(__x86_64__)
+ /*
+ * If we started a child process pass the signal on to it...
+ */
+
if (child_pid)
{
/*
exit(CUPS_BACKEND_STOP);
}
}
-}
-
#endif /* __i386__ || __x86_64__ */
+}
#ifdef PARSE_PS_ERRORS