Index: scheduler/quotas.c =================================================================== --- scheduler/quotas.c (revision 8293) +++ scheduler/quotas.c (working copy) @@ -3,7 +3,7 @@ * * Quota routines for the Common UNIX Printing System (CUPS). * - * Copyright 2007 by Apple Inc. + * Copyright 2007-2009 by Apple Inc. * Copyright 1997-2007 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -155,10 +155,22 @@ job; job = (cupsd_job_t *)cupsArrayNext(Jobs)) { + /* + * We only care about the current printer/class and user... + */ + if (strcasecmp(job->dest, p->name) != 0 || strcasecmp(job->username, q->username) != 0) continue; + /* + * Make sure attributes are loaded; we always call cupsdLoadJob() to ensure + * the access_time member is updated so the job isn't unloaded right away... + */ + + if (!cupsdLoadJob(job)) + continue; + if ((attr = ippFindAttribute(job->attrs, "time-at-completion", IPP_TAG_INTEGER)) == NULL) if ((attr = ippFindAttribute(job->attrs, "time-at-processing", @@ -166,11 +178,22 @@ attr = ippFindAttribute(job->attrs, "time-at-creation", IPP_TAG_INTEGER); - if (attr == NULL) - break; + if (!attr) + { + /* + * This should never happen since cupsdLoadJob() checks for + * time-at-creation, but if it does just ignore this job... + */ + continue; + } + if (attr->values[0].integer < curtime) { + /* + * This job is too old to count towards the quota, ignore it... + */ + if (JobAutoPurge) cupsdCancelJob(job, 1, IPP_JOB_CANCELED); Index: scheduler/job.c =================================================================== --- scheduler/job.c (revision 8293) +++ scheduler/job.c (working copy) @@ -3,7 +3,7 @@ * * Job management routines for the Common UNIX Printing System (CUPS). * - * Copyright 2007-2008 by Apple Inc. + * Copyright 2007-2009 by Apple Inc. * Copyright 1997-2007 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the @@ -1019,7 +1019,7 @@ * 'cupsdLoadJob()' - Load a single job... */ -void +int /* O - 1 on success, 0 on failure */ cupsdLoadJob(cupsd_job_t *job) /* I - Job */ { char jobfile[1024]; /* Job filename */ @@ -1037,14 +1037,14 @@ if (job->state_value > IPP_JOB_STOPPED) job->access_time = time(NULL); - return; + return (1); } if ((job->attrs = ippNew()) == NULL) { cupsdLogMessage(CUPSD_LOG_ERROR, "[Job %d] Ran out of memory for job attributes!", job->id); - return; + return (0); } /* @@ -1059,9 +1059,7 @@ cupsdLogMessage(CUPSD_LOG_ERROR, "[Job %d] Unable to open job control file \"%s\" - %s!", job->id, jobfile, strerror(errno)); - ippDelete(job->attrs); - job->attrs = NULL; - return; + goto error; } if (ippReadIO(fp, (ipp_iocb_t)cupsFileRead, 1, NULL, job->attrs) != IPP_DATA) @@ -1070,10 +1068,7 @@ "[Job %d] Unable to read job control file \"%s\"!", job->id, jobfile); cupsFileClose(fp); - ippDelete(job->attrs); - job->attrs = NULL; - unlink(jobfile); - return; + goto error; } cupsFileClose(fp); @@ -1087,10 +1082,7 @@ cupsdLogMessage(CUPSD_LOG_ERROR, "[Job %d] Missing or bad time-at-creation attribute in " "control file!", job->id); - ippDelete(job->attrs); - job->attrs = NULL; - unlink(jobfile); - return; + goto error; } if ((job->state = ippFindAttribute(job->attrs, "job-state", @@ -1100,10 +1092,7 @@ "[Job %d] Missing or bad job-state attribute in " "control file!", job->id); - ippDelete(job->attrs); - job->attrs = NULL; - unlink(jobfile); - return; + goto error; } job->state_value = (ipp_jstate_t)job->state->values[0].integer; @@ -1116,10 +1105,7 @@ cupsdLogMessage(CUPSD_LOG_ERROR, "[Job %d] No job-printer-uri attribute in control file!", job->id); - ippDelete(job->attrs); - job->attrs = NULL; - unlink(jobfile); - return; + goto error; } if ((dest = cupsdValidateDest(attr->values[0].string.text, &(job->dtype), @@ -1128,10 +1114,7 @@ cupsdLogMessage(CUPSD_LOG_ERROR, "[Job %d] Unable to queue job for destination \"%s\"!", job->id, attr->values[0].string.text); - ippDelete(job->attrs); - job->attrs = NULL; - unlink(jobfile); - return; + goto error; } cupsdSetString(&job->dest, dest); @@ -1141,10 +1124,7 @@ cupsdLogMessage(CUPSD_LOG_ERROR, "[Job %d] Unable to queue job for destination \"%s\"!", job->id, job->dest); - ippDelete(job->attrs); - job->attrs = NULL; - unlink(jobfile); - return; + goto error; } job->sheets = ippFindAttribute(job->attrs, "job-media-sheets-completed", @@ -1159,10 +1139,7 @@ cupsdLogMessage(CUPSD_LOG_ERROR, "[Job %d] Missing or bad job-priority attribute in " "control file!", job->id); - ippDelete(job->attrs); - job->attrs = NULL; - unlink(jobfile); - return; + goto error; } job->priority = attr->values[0].integer; @@ -1176,10 +1153,7 @@ cupsdLogMessage(CUPSD_LOG_ERROR, "[Job %d] Missing or bad job-originating-user-name " "attribute in control file!", job->id); - ippDelete(job->attrs); - job->attrs = NULL; - unlink(jobfile); - return; + goto error; } cupsdSetString(&job->username, attr->values[0].string.text); @@ -1248,7 +1222,7 @@ cupsdLogMessage(CUPSD_LOG_ERROR, "[Job %d] Ran out of memory for job file types!", job->id); - return; + return (1); } job->compressions = compressions; @@ -1304,7 +1278,20 @@ cupsFileClose(fp); } } + job->access_time = time(NULL); + return (1); + + /* + * If we get here then something bad happened... + */ + + error: + + ippDelete(job->attrs); + job->attrs = NULL; + unlink(jobfile); + return (0); } Index: scheduler/job.h =================================================================== --- scheduler/job.h (revision 8293) +++ scheduler/job.h (working copy) @@ -3,7 +3,7 @@ * * Print job definitions for the Common UNIX Printing System (CUPS) scheduler. * - * Copyright 2007-2008 by Apple Inc. + * Copyright 2007-2009 by Apple Inc. * Copyright 1997-2007 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the @@ -112,7 +112,7 @@ extern int cupsdGetUserJobCount(const char *username); extern void cupsdHoldJob(cupsd_job_t *job); extern void cupsdLoadAllJobs(void); -extern void cupsdLoadJob(cupsd_job_t *job); +extern int cupsdLoadJob(cupsd_job_t *job); extern void cupsdMoveJob(cupsd_job_t *job, cupsd_printer_t *p); extern void cupsdReleaseJob(cupsd_job_t *job); extern void cupsdRestartJob(cupsd_job_t *job);