]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/job.c
Fix source file header text duplication text duplication.
[thirdparty/cups.git] / scheduler / job.c
index 82c5306d635be268d837226f8ab9ccfac6eaf573..1b12fe5a152826774544c93db180c94678e0b82b 100644 (file)
@@ -1,16 +1,14 @@
 /*
- * "$Id$"
- *
  * Job management routines for the CUPS scheduler.
  *
- * Copyright 2007-2015 by Apple Inc.
+ * Copyright 2007-2016 by Apple Inc.
  * Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  * These coded instructions, statements, and computer programs are the
  * property of Apple Inc. and are protected by Federal copyright
  * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
  * which should have been included with this file.  If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * missing or damaged, see the license at "http://www.cups.org/".
  */
 
 /*
@@ -213,8 +211,6 @@ cupsdCancelJobs(const char *dest,   /* I - Destination to cancel */
                         "Job canceled by user.");
     }
   }
-
-  cupsdCheckJobs();
 }
 
 
@@ -231,6 +227,7 @@ cupsdCheckJobs(void)
                        *pclass;        /* Printer class destination */
   ipp_attribute_t      *attr;          /* Job attribute */
   time_t               curtime;        /* Current time */
+  const char           *reasons;       /* job-state-reasons value */
 
 
   curtime = time(NULL);
@@ -324,6 +321,25 @@ cupsdCheckJobs(void)
        ((FilterLevel + job->pending_cost) < FilterLimit || FilterLevel == 0))
       cupsdContinueJob(job);
 
+   /*
+    * Skip jobs that where held-on-create
+    */
+
+    reasons = ippGetString(job->reasons, 0, NULL);
+    if (reasons && !strcmp(reasons, "job-held-on-create"))
+    {
+     /*
+      * Check whether the printer is still holding new jobs...
+      */
+
+      printer = cupsdFindDest(job->dest);
+
+      if (printer->holding_new_jobs)
+        continue;
+
+      ippSetString(job->attrs, &job->reasons, 0, "none");
+    }
+
    /*
     * Start pending jobs if the destination is available...
     */
@@ -361,7 +377,7 @@ cupsdCheckJobs(void)
                         "Job aborted because the destination printer/class "
                         "has gone away.");
       }
-      else if (printer && !printer->holding_new_jobs)
+      else if (printer)
       {
        /*
         * See if the printer is available or remote and not printing a job;
@@ -371,16 +387,14 @@ cupsdCheckJobs(void)
         if (pclass)
        {
         /*
-         * Add/update a job-actual-printer-uri attribute for this job
+         * Add/update a job-printer-uri-actual attribute for this job
          * so that we know which printer actually printed the job...
          */
 
-          if ((attr = ippFindAttribute(job->attrs, "job-actual-printer-uri",
-                                      IPP_TAG_URI)) != NULL)
+          if ((attr = ippFindAttribute(job->attrs, "job-printer-uri-actual", IPP_TAG_URI)) != NULL)
             ippSetString(job->attrs, &attr, 0, printer->uri);
          else
-           ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_URI,
-                        "job-actual-printer-uri", NULL, printer->uri);
+           ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_URI, "job-printer-uri-actual", NULL, printer->uri);
 
           job->dirty = 1;
           cupsdMarkDirty(CUPSD_DIRTY_JOBS);
@@ -444,6 +458,8 @@ cupsdCleanJobs(void)
         cupsdLogJob(job, CUPSD_LOG_DEBUG, "Removing document files.");
         remove_job_files(job);
 
+        cupsdMarkDirty(CUPSD_DIRTY_JOBS);
+
         if (job->history_time < JobHistoryUpdate || !JobHistoryUpdate)
          JobHistoryUpdate = job->history_time;
       }
@@ -732,8 +748,8 @@ cupsdContinueJob(cupsd_job_t *job)  /* I - Job */
   * Add decompression/raw filter as needed...
   */
 
-  if (job->compressions[job->current_file] &&
-      (!job->printer->remote || job->num_files == 1))
+  if ((job->compressions[job->current_file] && (!job->printer->remote || job->num_files == 1)) ||
+      (!job->printer->remote && job->printer->raw && job->num_files > 1))
   {
    /*
     * Add gziptoany filter to the front of the list...
@@ -2195,6 +2211,15 @@ cupsdSaveAllJobs(void)
        job;
        job = (cupsd_job_t *)cupsArrayNext(Jobs))
   {
+    if (job->printer && job->printer->temporary)
+    {
+     /*
+      * Don't save jobs on temporary printers...
+      */
+
+      continue;
+    }
+
     cupsFilePrintf(fp, "<Job %d>\n", job->id);
     cupsFilePrintf(fp, "State %d\n", job->state_value);
     cupsFilePrintf(fp, "Created %ld\n", (long)job->creation_time);
@@ -2234,6 +2259,16 @@ cupsdSaveJob(cupsd_job_t *job)           /* I - Job */
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdSaveJob(job=%p(%d)): job->attrs=%p",
                   job, job->id, job->attrs);
 
+  if (job->printer && job->printer->temporary)
+  {
+   /*
+    * Don't save jobs on temporary printers...
+    */
+
+    job->dirty = 0;
+    return;
+  }
+
   snprintf(filename, sizeof(filename), "%s/c%05d", RequestRoot, job->id);
 
   if ((fp = cupsdCreateConfFile(filename, ConfigFilePerm & 0600)) == NULL)
@@ -2316,7 +2351,10 @@ cupsdSetJobHoldUntil(cupsd_job_t *job,   /* I - Job */
 
   }
 
-  ippSetString(job->attrs, &job->reasons, 0, "job-hold-until-specified");
+  if (strcmp(when, "no-hold"))
+    ippSetString(job->attrs, &job->reasons, 0, "job-hold-until-specified");
+  else
+    ippSetString(job->attrs, &job->reasons, 0, "none");
 
  /*
   * Update the hold time...
@@ -2786,7 +2824,8 @@ cupsdUnloadCompletedJobs(void)
       if (job->dirty)
         cupsdSaveJob(job);
 
-      unload_job(job);
+      if (!job->dirty)
+        unload_job(job);
     }
 }
 
@@ -3167,7 +3206,7 @@ finalize_job(cupsd_job_t *job,            /* I - Job */
 
    /*
     * Convert the status to an exit code.  Due to the way the W* macros are
-    * implemented on MacOS X (bug?), we have to store the exit status in a
+    * implemented on macOS (bug?), we have to store the exit status in a
     * variable first and then convert...
     */
 
@@ -3505,6 +3544,13 @@ finalize_job(cupsd_job_t *job,           /* I - Job */
 
   cupsArrayRemove(PrintingJobs, job);
 
+ /*
+  * Clear informational messages...
+  */
+
+  if (job->status_level > CUPSD_LOG_ERROR)
+    job->printer->state_message[0] = '\0';
+
  /*
   * Apply any PPD updates...
   */
@@ -3526,13 +3572,6 @@ finalize_job(cupsd_job_t *job,           /* I - Job */
 
   job->printer->job = NULL;
   job->printer      = NULL;
-
- /*
-  * Try printing another job...
-  */
-
-  if (printer_state != IPP_PRINTER_STOPPED)
-    cupsdCheckJobs();
 }
 
 
@@ -4120,7 +4159,15 @@ load_job_cache(const char *filename)     /* I - job.cache filename */
        {
          cupsdLogMessage(CUPSD_LOG_ERROR, "[Job %d] Files have gone away.",
                          jobid);
-         continue;
+
+         /*
+          * job.cache file is out-of-date compared to spool directory; load
+          * that instead...
+          */
+
+         cupsFileClose(fp);
+          load_request_root();
+          return;
        }
       }
 
@@ -4849,6 +4896,8 @@ update_job(cupsd_job_t *job)              /* I - Job to check */
                *ptr;                   /* Pointer update... */
   int          loglevel,               /* Log level for message */
                event = 0;              /* Events? */
+  cupsd_printer_t *printer = job->printer;
+                                       /* Printer */
   static const char * const levels[] = /* Log levels */
                {
                  "NONE",
@@ -5141,7 +5190,7 @@ update_job(cupsd_job_t *job)              /* I - Job to check */
         ptr = message;
 
       if (*ptr)
-        cupsdLogJob(job, loglevel, "%s", ptr);
+        cupsdLogJob(job, loglevel == CUPSD_LOG_INFO ? CUPSD_LOG_DEBUG : loglevel, "%s", ptr);
 
       if (loglevel < CUPSD_LOG_DEBUG &&
           strcmp(job->printer->state_message, ptr))
@@ -5222,10 +5271,11 @@ update_job(cupsd_job_t *job)            /* I - Job to check */
     finalize_job(job, 1);
 
    /*
-    * Check for new jobs...
+    * Try printing another job...
     */
 
-    cupsdCheckJobs();
+    if (printer->state != IPP_PRINTER_STOPPED)
+      cupsdCheckJobs();
   }
 }
 
@@ -5342,8 +5392,3 @@ update_job_attrs(cupsd_job_t *job,        /* I - Job to update */
   job->dirty = 1;
   cupsdMarkDirty(CUPSD_DIRTY_JOBS);
 }
-
-
-/*
- * End of "$Id$".
- */