From: Michael Sweet Date: Thu, 25 May 2017 18:02:12 +0000 (-0400) Subject: Delete temporary printers periodically and on shutdown (Issue #5003) X-Git-Tag: v2.2.4~67 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b497414286c418fd0a3705834ea7029b9afddec2;p=thirdparty%2Fcups.git Delete temporary printers periodically and on shutdown (Issue #5003) --- diff --git a/CHANGES.md b/CHANGES.md index 3e0d9d8a41..9e7f7ace20 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,4 @@ -CHANGES - 2.2.4 - 2017-05-17 +CHANGES - 2.2.4 - 2017-05-25 ============================ CHANGES IN CUPS V2.2.4 @@ -16,6 +16,8 @@ CHANGES IN CUPS V2.2.4 - IPP Everywhere improvements (Issue #4998) - Fixed the "cancel all jobs" function in the web interface for several languages (Issue #4999) +- The scheduler was not deleting temporary queues, leaving behind PPD files + (Issue #5003) CHANGES IN CUPS V2.2.3 diff --git a/scheduler/main.c b/scheduler/main.c index bdb27a6db6..bdfddf983a 100644 --- a/scheduler/main.c +++ b/scheduler/main.c @@ -1022,7 +1022,10 @@ main(int argc, /* I - Number of command-line args */ */ if (JobHistoryUpdate && current_time >= JobHistoryUpdate) + { cupsdCleanJobs(); + cupsdDeleteTemporaryPrinters(0); + } /* * Log statistics at most once a minute when in debug mode... @@ -1152,6 +1155,12 @@ main(int argc, /* I - Number of command-line args */ cupsdFreeAllJobs(); + /* + * Delete all temporary printers... + */ + + cupsdDeleteTemporaryPrinters(1); + #ifdef __APPLE__ /* * Stop monitoring system event monitoring... @@ -1631,13 +1640,13 @@ select_timeout(int fds) /* I - Number of descriptors returned */ #ifdef __APPLE__ /* - * When going to sleep, wake up to cancel jobs that don't complete in time. + * When going to sleep, wake up to abort jobs that don't complete in time. */ if (SleepJobs > 0 && SleepJobs < timeout) { timeout = SleepJobs; - why = "cancel jobs before sleeping"; + why = "abort jobs before sleeping"; } #endif /* __APPLE__ */ diff --git a/scheduler/printers.c b/scheduler/printers.c index e17d331eee..1c81c5504d 100644 --- a/scheduler/printers.c +++ b/scheduler/printers.c @@ -756,11 +756,6 @@ cupsdDeletePrinter( * Remove any old PPD or script files... */ - snprintf(filename, sizeof(filename), "%s/interfaces/%s", ServerRoot, p->name); - unlink(filename); - snprintf(filename, sizeof(filename), "%s/interfaces/%s.O", ServerRoot, p->name); - unlink(filename); - snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot, p->name); unlink(filename); snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd.O", ServerRoot, p->name); @@ -839,6 +834,32 @@ cupsdDeletePrinter( } +/* + * 'cupsdDeleteTemporaryPrinters()' - Delete unneeded temporary printers. + */ + +void +cupsdDeleteTemporaryPrinters(int force) /* I - Force deletion instead of auto? */ +{ + cupsd_printer_t *p; /* Current printer */ + time_t unused_time; /* Last time for printer state change */ + + + /* + * Allow temporary printers to stick around for 60 seconds after the last job + * completes. + */ + + unused_time = time(NULL) - 60; + + for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); p; p = (cupsd_printer_t *)cupsArrayNext(Printers)) + { + if (p->temporary && (force || p->state_time < unused_time)) + cupsdDeletePrinter(p, 0); + } +} + + /* * 'cupsdFindDest()' - Find a destination in the list. */ diff --git a/scheduler/printers.h b/scheduler/printers.h index c63b4711f0..e1d991016a 100644 --- a/scheduler/printers.h +++ b/scheduler/printers.h @@ -1,7 +1,7 @@ /* * Printer definitions for the CUPS scheduler. * - * Copyright 2007-2016 by Apple Inc. + * Copyright 2007-2017 by Apple Inc. * Copyright 1997-2007 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the @@ -156,6 +156,7 @@ extern cupsd_printer_t *cupsdAddPrinter(const char *name); extern void cupsdCreateCommonData(void); extern void cupsdDeleteAllPrinters(void); extern int cupsdDeletePrinter(cupsd_printer_t *p, int update); +extern void cupsdDeleteTemporaryPrinters(int force); extern cupsd_printer_t *cupsdFindDest(const char *name); extern cupsd_printer_t *cupsdFindPrinter(const char *name); extern cupsd_quota_t *cupsdFindQuota(cupsd_printer_t *p,