File SUSE_bsc_1195115.patch of Package cups.29369

From a85f8c00323c6e9f20af21b32295ba1a7abb3daf Mon Sep 17 00:00:00 2001
From: Michael R Sweet <michael.r.sweet@gmail.com>
Date: Wed, 16 Mar 2022 04:52:47 +0100
Subject: [PATCH 1/1] Fix an issue with  and time values (Issue #5538)

---
 scheduler/job.c       | 36 ++++++++++++++++++------------------
 test/run-stp-tests.sh |  2 +-
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/scheduler/job.c b/scheduler/job.c
index ed8267d..aee2fae 100644
--- a/scheduler/job.c
+++ b/scheduler/job.c
@@ -437,10 +437,20 @@ cupsdCleanJobs(void)
   curtime          = time(NULL);
   JobHistoryUpdate = 0;
 
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdCleanJobs: curtime=%d", (int)curtime);
+
   for (job = (cupsd_job_t *)cupsArrayFirst(Jobs);
        job;
        job = (cupsd_job_t *)cupsArrayNext(Jobs))
   {
+    cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdCleanJobs: Job %d, state=%d, printer=%p, history_time=%d, file_time=%d", job->id, (int)job->state_value, (void *)job->printer, (int)job->history_time, (int)job->file_time);
+
+    if ((job->history_time && job->history_time) < JobHistoryUpdate || !JobHistoryUpdate)
+      JobHistoryUpdate = job->history_time;
+
+    if ((job->file_time && job->file_time < JobHistoryUpdate) || !JobHistoryUpdate)
+      JobHistoryUpdate = job->file_time;
+
     if (job->state_value >= IPP_JOB_CANCELED && !job->printer)
     {
      /*
@@ -456,21 +466,9 @@ cupsdCleanJobs(void)
       else if (job->file_time && job->file_time <= curtime)
       {
         cupsdLogJob(job, CUPSD_LOG_DEBUG, "Removing document files.");
-        cupsdLogJob(job, CUPSD_LOG_DEBUG2, "curtime=%ld, job->file_time=%ld", (long)curtime, (long)job->file_time);
         remove_job_files(job);
 
         cupsdMarkDirty(CUPSD_DIRTY_JOBS);
-
-        if (job->history_time < JobHistoryUpdate || !JobHistoryUpdate)
-	  JobHistoryUpdate = job->history_time;
-      }
-      else
-      {
-        if (job->history_time < JobHistoryUpdate || !JobHistoryUpdate)
-	  JobHistoryUpdate = job->history_time;
-
-	if (job->file_time < JobHistoryUpdate || !JobHistoryUpdate)
-	  JobHistoryUpdate = job->file_time;
       }
     }
   }
@@ -1729,7 +1727,7 @@ cupsdLoadJob(cupsd_job_t *job)		/* I - Job */
     job->completed_time = attr->values[0].integer;
 
     if (JobHistory < INT_MAX)
-      job->history_time = attr->values[0].integer + JobHistory;
+      job->history_time = job->completed_time + JobHistory;
     else
       job->history_time = INT_MAX;
 
@@ -1740,7 +1738,7 @@ cupsdLoadJob(cupsd_job_t *job)		/* I - Job */
       JobHistoryUpdate = job->history_time;
 
     if (JobFiles < INT_MAX)
-      job->file_time = attr->values[0].integer + JobFiles;
+      job->file_time = job->completed_time + JobFiles;
     else
       job->file_time = INT_MAX;
 
@@ -2860,8 +2858,10 @@ cupsdUpdateJobs(void)
       * Update history/file expiration times...
       */
 
+      job->completed_time = attr->values[0].integer;
+
       if (JobHistory < INT_MAX)
-	job->history_time = attr->values[0].integer + JobHistory;
+	job->history_time = job->completed_time + JobHistory;
       else
 	job->history_time = INT_MAX;
 
@@ -2875,7 +2875,7 @@ cupsdUpdateJobs(void)
 	JobHistoryUpdate = job->history_time;
 
       if (JobFiles < INT_MAX)
-	job->file_time = attr->values[0].integer + JobFiles;
+	job->file_time = job->completed_time + JobFiles;
       else
 	job->file_time = INT_MAX;
 
@@ -4656,7 +4656,7 @@ set_time(cupsd_job_t *job,		/* I - Job to update */
     job->completed_time = curtime;
 
     if (JobHistory < INT_MAX && attr)
-      job->history_time = attr->values[0].integer + JobHistory;
+      job->history_time = job->completed_time + JobHistory;
     else
       job->history_time = INT_MAX;
 
@@ -4664,7 +4664,7 @@ set_time(cupsd_job_t *job,		/* I - Job to update */
       JobHistoryUpdate = job->history_time;
 
     if (JobFiles < INT_MAX && attr)
-      job->file_time = curtime + JobFiles;
+      job->file_time = job->completed_time + JobFiles;
     else
       job->file_time = INT_MAX;
 
diff --git a/test/run-stp-tests.sh b/test/run-stp-tests.sh
index 056e8e5..92dfb99 100755
--- a/test/run-stp-tests.sh
+++ b/test/run-stp-tests.sh
@@ -930,7 +930,7 @@ fi
 
 # Requests logged
 count=`wc -l $BASE/log/access_log | awk '{print $1}'`
-expected=`expr 37 + 18 + 30 + $pjobs \* 8 + $pprinters \* $pjobs \* 4`
+expected=`expr 35 + 18 + 30 + $pjobs \* 8 + $pprinters \* $pjobs \* 4 + 2`
 if test $count != $expected; then
 	echo "FAIL: $count requests logged, expected $expected."
 	echo "    <p>FAIL: $count requests logged, expected $expected.</p>" >>$strfile
-- 
2.26.2

openSUSE Build Service is sponsored by