/*
- * "$Id$"
+ * "$Id: job.c 5889 2006-08-24 21:44:35Z mike $"
*
* Job management routines for the Common UNIX Printing System (CUPS).
*
*/
cupsdLogMessage(CUPSD_LOG_WARN,
- "Printer/class %s has gone away; cancelling job %d!",
+ "Printer/class %s has gone away; canceling job %d!",
job->dest, job->id);
cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
*/
cupsdStopJob(job, 0);
- job->state->values[0].integer = IPP_JOB_PENDING;
- job->state_value = IPP_JOB_PENDING;
+
+ if (!(printer->type & CUPS_PRINTER_REMOTE) ||
+ (printer->type & CUPS_PRINTER_IMPLICIT))
+ {
+ /*
+ * Mark the job as pending again - we'll retry on another
+ * printer...
+ */
+
+ job->state->values[0].integer = IPP_JOB_PENDING;
+ job->state_value = IPP_JOB_PENDING;
+ }
+
cupsdSaveJob(job);
/*
cupsdHoldSignals();
- cupsdStopAllJobs();
+ cupsdStopAllJobs(1);
cupsdSaveAllJobs();
for (job = (cupsd_job_t *)cupsArrayFirst(Jobs);
*/
void
-cupsdStopAllJobs(void)
+cupsdStopAllJobs(int force) /* I - 1 = Force all filters to stop */
{
cupsd_job_t *job; /* Current job */
job = (cupsd_job_t *)cupsArrayNext(ActiveJobs))
if (job->state_value == IPP_JOB_PROCESSING)
{
- cupsdStopJob(job, 1);
+ cupsdStopJob(job, force);
job->state->values[0].integer = IPP_JOB_PENDING;
job->state_value = IPP_JOB_PENDING;
}
break;
}
- if (ptr == NULL)
+ if (ptr == NULL && !job->status_buffer->bufused)
{
/*
* See if all of the filters and the backend have returned their
int diff; /* Difference */
- if ((diff = ((cupsd_job_t *)first)->priority -
- ((cupsd_job_t *)second)->priority) != 0)
+ if ((diff = ((cupsd_job_t *)second)->priority -
+ ((cupsd_job_t *)first)->priority) != 0)
return (diff);
else
return (((cupsd_job_t *)first)->id - ((cupsd_job_t *)second)->id);
}
else if (!strcasecmp(line, "State"))
{
- job->state_value = atoi(value);
+ job->state_value = (ipp_jstate_t)atoi(value);
if (job->state_value < IPP_JOB_PENDING)
job->state_value = IPP_JOB_PENDING;
/* PRINTER env variable */
rip_max_cache[255];
/* RIP_MAX_CACHE env variable */
- int remote_job; /* Remote print job? */
static char *options = NULL;/* Full list of options */
static int optlength = 0; /* Length of option buffer */
if (job->num_files == 0)
{
- cupsdLogMessage(CUPSD_LOG_ERROR, "Job ID %d has no files! Cancelling it!",
+ cupsdLogMessage(CUPSD_LOG_ERROR, "Job ID %d has no files! Canceling it!",
job->id);
cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
FilterLevel += job->cost;
- /*
- * Determine if we are printing to a remote printer...
- */
-
- remote_job = printer->raw && job->num_files > 1 &&
- !strncmp(printer->device_uri, "ipp://", 6);
-
/*
* Add decompression filters, if any...
*/
- if (!remote_job && job->compressions[job->current_file])
+ if (!printer->raw && job->compressions[job->current_file])
{
/*
* Add gziptoany filter to the front of the list...
* For remote jobs, we send all of the files in the argument list.
*/
- if (remote_job)
+ if (printer->remote && job->num_files > 1)
argv = calloc(7 + job->num_files, sizeof(char *));
else
argv = calloc(8, sizeof(char *));
argv[4] = copies;
argv[5] = options;
- if (remote_job)
+ if (printer->remote && job->num_files > 1)
{
for (i = 0; i < job->num_files; i ++)
{
envp[envc ++] = device_uri;
envp[envc ++] = printer_name;
- if ((filter = (mime_filter_t *)cupsArrayLast(filters)) != NULL)
+ if (!printer->remote &&
+ (filter = (mime_filter_t *)cupsArrayLast(filters)) != NULL)
{
snprintf(final_content_type, sizeof(final_content_type),
"FINAL_CONTENT_TYPE=%s/%s",
cupsdLogMessage(CUPSD_LOG_DEBUG, "[Job %d] envp[%d]=\"DEVICE_URI=%s\"",
job->id, i, sani_uri);
- if (remote_job)
+ if (printer->remote)
job->current_file = job->num_files;
else
job->current_file ++;
job->status = 0;
memset(job->filters, 0, sizeof(job->filters));
- filterfds[1][0] = open("/dev/null", O_RDONLY);
-
- if (filterfds[1][0] < 0)
- {
- cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open \"/dev/null\" - %s.",
- strerror(errno));
- snprintf(printer->state_message, sizeof(printer->state_message),
- "Unable to open \"/dev/null\" - %s.", strerror(errno));
-
- cupsdAddPrinterHistory(printer);
-
- cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
- "Job canceled because the server could not open /dev/null.");
-
- goto abort_job;
- }
-
- fcntl(filterfds[1][0], F_SETFD, fcntl(filterfds[1][0], F_GETFD) | FD_CLOEXEC);
-
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "start_job: filterfds[%d] = [ %d %d ]",
- 1, filterfds[1][0], filterfds[1][1]);
-
for (i = 0, slot = 0, filter = (mime_filter_t *)cupsArrayFirst(filters);
filter;
i ++, filter = (mime_filter_t *)cupsArrayNext(filters))
else
{
job->print_pipes[0] = -1;
- if (!strncmp(printer->device_uri, "file:/dev/", 10) &&
- strcmp(printer->device_uri, "file:/dev/null"))
- job->print_pipes[1] = open(printer->device_uri + 5,
- O_WRONLY | O_EXCL);
- else if (!strncmp(printer->device_uri, "file:///dev/", 12) &&
- strcmp(printer->device_uri, "file:///dev/null"))
- job->print_pipes[1] = open(printer->device_uri + 7,
- O_WRONLY | O_EXCL);
+ if (!strcmp(printer->device_uri, "file:/dev/null") ||
+ !strcmp(printer->device_uri, "file:///dev/null"))
+ job->print_pipes[1] = -1;
else
- job->print_pipes[1] = open(printer->device_uri + 5,
- O_WRONLY | O_CREAT | O_TRUNC, 0600);
-
- if (job->print_pipes[1] < 0)
{
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "Unable to open output file \"%s\" - %s.",
- printer->device_uri, strerror(errno));
- snprintf(printer->state_message, sizeof(printer->state_message),
- "Unable to open output file \"%s\" - %s.",
- printer->device_uri, strerror(errno));
-
- cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
- "Job canceled because the server could not open the "
- "output file.");
+ if (!strncmp(printer->device_uri, "file:/dev/", 10))
+ job->print_pipes[1] = open(printer->device_uri + 5,
+ O_WRONLY | O_EXCL);
+ else if (!strncmp(printer->device_uri, "file:///dev/", 12))
+ job->print_pipes[1] = open(printer->device_uri + 7,
+ O_WRONLY | O_EXCL);
+ else if (!strncmp(printer->device_uri, "file:///", 8))
+ job->print_pipes[1] = open(printer->device_uri + 7,
+ O_WRONLY | O_CREAT | O_TRUNC, 0600);
+ else
+ job->print_pipes[1] = open(printer->device_uri + 5,
+ O_WRONLY | O_CREAT | O_TRUNC, 0600);
- goto abort_job;
- }
+ if (job->print_pipes[1] < 0)
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Unable to open output file \"%s\" - %s.",
+ printer->device_uri, strerror(errno));
+ snprintf(printer->state_message, sizeof(printer->state_message),
+ "Unable to open output file \"%s\" - %s.",
+ printer->device_uri, strerror(errno));
+
+ cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
+ "Job canceled because the server could not open the "
+ "output file.");
+
+ goto abort_job;
+ }
- fcntl(job->print_pipes[1], F_SETFD,
- fcntl(job->print_pipes[1], F_GETFD) | FD_CLOEXEC);
+ fcntl(job->print_pipes[1], F_SETFD,
+ fcntl(job->print_pipes[1], F_GETFD) | FD_CLOEXEC);
+ }
}
cupsdLogMessage(CUPSD_LOG_DEBUG2,
argv[0] = sani_uri;
filterfds[slot][0] = -1;
- filterfds[slot][1] = open("/dev/null", O_WRONLY);
-
- if (filterfds[slot][1] < 0)
- {
- cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open \"/dev/null\" - %s.",
- strerror(errno));
- snprintf(printer->state_message, sizeof(printer->state_message),
- "Unable to open \"/dev/null\" - %s.", strerror(errno));
-
- cupsdAddPrinterHistory(printer);
-
- cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
- "Job canceled because the server could not open a file.");
-
- goto abort_job;
- }
-
- fcntl(filterfds[slot][1], F_SETFD,
- fcntl(filterfds[slot][1], F_GETFD) | FD_CLOEXEC);
+ filterfds[slot][1] = -1;
cupsdLogMessage(CUPSD_LOG_DEBUG2, "start_job: backend=\"%s\"",
command);
slot, filterfds[slot][0], filterfds[slot][1]);
cupsdClosePipe(filterfds[slot]);
- if (remote_job)
+ if (printer->remote && job->num_files > 1)
{
for (i = 0; i < job->num_files; i ++)
free(argv[i + 6]);
cupsArrayDelete(filters);
- if (remote_job)
+ if (printer->remote && job->num_files > 1)
{
for (i = 0; i < job->num_files; i ++)
free(argv[i + 6]);
/*
- * End of "$Id$".
+ * End of "$Id: job.c 5889 2006-08-24 21:44:35Z mike $".
*/