From 4c9412687601aa32674218dd93b046f220777525 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Thu, 21 Feb 2019 11:04:14 -0500 Subject: [PATCH] The scheduler did not always idle exit as quickly as it could... --- CHANGES.md | 1 + scheduler/main.c | 26 ++++++++++++++++++-------- scheduler/server.c | 11 ++++++++++- scheduler/subscriptions.c | 5 ++++- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c66ca2054c..57bd5f85c0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -29,6 +29,7 @@ Changes in CUPS v2.2.11 names for the server when using GNU TLS (Issue #5525) - Fixed a potential crash bug in cups-driverd (rdar://46625579) - Fixed a performance regression with large PPDs (rdar://47040759) +- The scheduler did not always idle exit as quickly as it could. Changes in CUPS v2.2.10 diff --git a/scheduler/main.c b/scheduler/main.c index a61592cd82..e96337086f 100644 --- a/scheduler/main.c +++ b/scheduler/main.c @@ -1,7 +1,7 @@ /* * Main loop for the CUPS scheduler. * - * Copyright 2007-2018 by Apple Inc. + * Copyright 2007-2019 by Apple Inc. * Copyright 1997-2007 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the @@ -807,15 +807,26 @@ main(int argc, /* I - Number of command-line args */ * inactivity... */ - if (timeout == 86400 && OnDemand && IdleExitTimeout && - !cupsArrayCount(ActiveJobs) && + if (OnDemand && IdleExitTimeout && # ifdef HAVE_SYSTEMD !WebInterface && # endif /* HAVE_SYSTEMD */ - (!Browsing || !BrowseLocalProtocols || !cupsArrayCount(Printers))) + !cupsArrayCount(ActiveJobs)) { - timeout = IdleExitTimeout; - service_idle_exit = 1; + cupsd_printer_t *p = NULL; /* Current printer */ + + if (Browsing && BrowseLocalProtocols) + { + for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); p; p = (cupsd_printer_t *)cupsArrayNext(Printers)) + if (p->shared) + break; + } + + if (!p) + { + timeout = IdleExitTimeout; + service_idle_exit = 1; + } } else service_idle_exit = 0; @@ -946,8 +957,7 @@ main(int argc, /* I - Number of command-line args */ if (current_time > expire_time) { - if (cupsArrayCount(Subscriptions) > 0) - cupsdExpireSubscriptions(NULL, NULL); + cupsdExpireSubscriptions(NULL, NULL); cupsdUnloadCompletedJobs(); diff --git a/scheduler/server.c b/scheduler/server.c index 63fcf90bf5..4714a61503 100644 --- a/scheduler/server.c +++ b/scheduler/server.c @@ -1,7 +1,7 @@ /* * Server start/stop routines for the CUPS scheduler. * - * Copyright 2007-2018 by Apple Inc. + * Copyright 2007-2019 by Apple Inc. * Copyright 1997-2006 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the @@ -176,6 +176,15 @@ cupsdStopServer(void) cupsdDestroyProfile(DefaultProfile); DefaultProfile = NULL; + /* + * Expire subscriptions and clean out old jobs... + */ + + cupsdExpireSubscriptions(NULL, NULL); + + if (JobHistoryUpdate) + cupsdCleanJobs(); + /* * Write out any dirty files... */ diff --git a/scheduler/subscriptions.c b/scheduler/subscriptions.c index b2abf14ee9..cac340520d 100644 --- a/scheduler/subscriptions.c +++ b/scheduler/subscriptions.c @@ -1,7 +1,7 @@ /* * Subscription routines for the CUPS scheduler. * - * Copyright 2007-2014 by Apple Inc. + * Copyright 2007-2019 by Apple Inc. * Copyright 1997-2007 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the @@ -652,6 +652,9 @@ cupsdExpireSubscriptions( time_t curtime; /* Current time */ + if (cupsArrayCount(Subscriptions) == 0) + return; + curtime = time(NULL); update = 0; -- 2.47.2