]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/job.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / job.c
index 9c04db1619548c4ffa0491325f9565e4b360812d..79370fbba9ed4545388dbbd9f714eac52a844b62 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id$"
+ * "$Id: job.c 5889 2006-08-24 21:44:35Z mike $"
  *
  *   Job management routines for the Common UNIX Printing System (CUPS).
  *
@@ -354,7 +354,7 @@ cupsdCheckJobs(void)
        */
 
         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,
@@ -506,8 +506,19 @@ cupsdFinishJob(cupsd_job_t *job)   /* I - 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);
 
         /*
@@ -679,7 +690,7 @@ cupsdFreeAllJobs(void)
 
   cupsdHoldSignals();
 
-  cupsdStopAllJobs();
+  cupsdStopAllJobs(1);
   cupsdSaveAllJobs();
 
   for (job = (cupsd_job_t *)cupsArrayFirst(Jobs);
@@ -1483,7 +1494,7 @@ cupsdSetJobPriority(
  */
 
 void
-cupsdStopAllJobs(void)
+cupsdStopAllJobs(int force)            /* I - 1 = Force all filters to stop */
 {
   cupsd_job_t  *job;                   /* Current job */
 
@@ -1495,7 +1506,7 @@ cupsdStopAllJobs(void)
        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;
     }
@@ -1717,7 +1728,7 @@ cupsdUpdateJob(cupsd_job_t *job)  /* I - Job to check */
       break;
   }
 
-  if (ptr == NULL)
+  if (ptr == NULL && !job->status_buffer->bufused)
   {
    /*
     * See if all of the filters and the backend have returned their
@@ -1753,8 +1764,8 @@ compare_active_jobs(void *first,  /* I - First job */
   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);
@@ -2042,7 +2053,7 @@ load_job_cache(const char *filename)      /* I - job.cache filename */
     }
     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;
@@ -2414,7 +2425,6 @@ start_job(cupsd_job_t     *job,           /* I - Job ID */
                                        /* 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 */
 
@@ -2424,7 +2434,7 @@ start_job(cupsd_job_t     *job,           /* I - Job ID */
 
   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,
@@ -2555,18 +2565,11 @@ start_job(cupsd_job_t     *job,         /* I - Job ID */
 
   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...
@@ -2900,7 +2903,7 @@ start_job(cupsd_job_t     *job,           /* I - Job ID */
   * 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 *));
@@ -2914,7 +2917,7 @@ start_job(cupsd_job_t     *job,           /* I - Job ID */
   argv[4] = copies;
   argv[5] = options;
 
-  if (remote_job)
+  if (printer->remote && job->num_files > 1)
   {
     for (i = 0; i < job->num_files; i ++)
     {
@@ -3007,7 +3010,8 @@ start_job(cupsd_job_t     *job,           /* I - Job ID */
   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",
@@ -3048,7 +3052,7 @@ start_job(cupsd_job_t     *job,           /* I - Job ID */
       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 ++;
@@ -3090,28 +3094,6 @@ start_job(cupsd_job_t     *job,          /* I - Job ID */
   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))
@@ -3165,36 +3147,43 @@ start_job(cupsd_job_t     *job,         /* I - Job ID */
        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,
@@ -3274,25 +3263,7 @@ start_job(cupsd_job_t     *job,          /* I - Job ID */
       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);
@@ -3377,7 +3348,7 @@ start_job(cupsd_job_t     *job,           /* I - Job ID */
                  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]);
@@ -3421,7 +3392,7 @@ start_job(cupsd_job_t     *job,           /* I - Job ID */
 
   cupsArrayDelete(filters);
 
-  if (remote_job)
+  if (printer->remote && job->num_files > 1)
   {
     for (i = 0; i < job->num_files; i ++)
       free(argv[i + 6]);
@@ -3455,5 +3426,5 @@ unload_job(cupsd_job_t *job)              /* I - Job */
 
 
 /*
- * End of "$Id$".
+ * End of "$Id: job.c 5889 2006-08-24 21:44:35Z mike $".
  */