From e4e371946b2ddb8adfb03c637992b0b3d3575f5f Mon Sep 17 00:00:00 2001 From: Michael Sweet Date: Mon, 2 Oct 2017 19:14:25 -0400 Subject: [PATCH] The scheduler did not run with a high enough priority, causing problems on busy systems (rdar://33789342) - Change ProcessType to Adaptive for both cupsd and cups-lpd - Add "working" parameter to cupsdSetBusyState - Call cupsdSetBusyState on startup to boost the priority on startup. --- CHANGES.md | 5 +++-- scheduler/client.c | 10 ++++++---- scheduler/cups-lpd.c | 1 - scheduler/job.c | 2 +- scheduler/main.c | 8 ++++++++ scheduler/org.cups.cups-lpd.plist.in | 2 +- scheduler/org.cups.cupsd.plist | 5 ++--- scheduler/server.c | 4 ++-- scheduler/sysman.c | 10 +++++----- scheduler/sysman.h | 4 ++-- 10 files changed, 30 insertions(+), 21 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 72038fc14..7eb6a862c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,4 @@ -CHANGES - 2.2.5 - 2017-09-25 +CHANGES - 2.2.5 - 2017-10-02 ============================ CHANGES IN CUPS V2.2.5 @@ -59,7 +59,8 @@ CHANGES IN CUPS V2.2.5 - The `ippCopyAttribute` function did not copy out-of-band values correctly (rdar://33688003) - Fixed the localization fallback code on macOS (rdar://33583699) -- The `ipptool` program now offers an option to validate response headers. +- The scheduler did not run with a high enough priority, causing problems on + busy systems (rdar://33789342) - The `ipptool` program's `-P` option did not work correctly. - The `ipptool` program did not compare URI scheme or hostname components correctly for the WITH-ALL-HOSTNAMES, WITH-ALL-SCHEMES, WITH-HOSTNAME, or diff --git a/scheduler/client.c b/scheduler/client.c index 78695ae65..d628dc6c3 100644 --- a/scheduler/client.c +++ b/scheduler/client.c @@ -85,6 +85,8 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */ if (cupsArrayCount(Clients) == MaxClients) return; + cupsdSetBusyState(1); + /* * Get a pointer to the next available client... */ @@ -439,7 +441,7 @@ cupsdCloseClient(cupsd_client_t *con) /* I - Client to close */ if (httpGetFd(con->http) >= 0) { cupsArrayRemove(ActiveClients, con); - cupsdSetBusyState(); + cupsdSetBusyState(0); #ifdef HAVE_SSL /* @@ -760,7 +762,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ if (!cupsArrayFind(ActiveClients, con)) { cupsArrayAdd(ActiveClients, con); - cupsdSetBusyState(); + cupsdSetBusyState(0); } case HTTP_STATE_OPTIONS : @@ -2082,7 +2084,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ else { cupsArrayRemove(ActiveClients, con); - cupsdSetBusyState(); + cupsdSetBusyState(0); } } } @@ -2807,7 +2809,7 @@ cupsdWriteClient(cupsd_client_t *con) /* I - Client connection */ else { cupsArrayRemove(ActiveClients, con); - cupsdSetBusyState(); + cupsdSetBusyState(0); } } } diff --git a/scheduler/cups-lpd.c b/scheduler/cups-lpd.c index 5d5e6f894..fbc69e102 100644 --- a/scheduler/cups-lpd.c +++ b/scheduler/cups-lpd.c @@ -103,7 +103,6 @@ main(int argc, /* I - Number of command-line arguments */ xpc_transaction_begin(); #endif /* __APPLE__ */ - /* * Don't buffer the output... */ diff --git a/scheduler/job.c b/scheduler/job.c index 9d281db6b..86e75e65c 100644 --- a/scheduler/job.c +++ b/scheduler/job.c @@ -2768,7 +2768,7 @@ cupsdSetJobState( * Update the server "busy" state... */ - cupsdSetBusyState(); + cupsdSetBusyState(0); } diff --git a/scheduler/main.c b/scheduler/main.c index 09735b83a..8925c8373 100644 --- a/scheduler/main.c +++ b/scheduler/main.c @@ -495,6 +495,12 @@ main(int argc, /* I - Number of command-line args */ exit(errno); } + /* + * Let the system know we are busy while we bring up cupsd... + */ + + cupsdSetBusyState(1); + /* * Set the timezone info... */ @@ -683,6 +689,8 @@ main(int argc, /* I - Number of command-line args */ else cupsdAddEvent(CUPSD_EVENT_SERVER_STARTED, NULL, NULL, "Scheduler started in background."); + cupsdSetBusyState(0); + /* * Start any pending print jobs... */ diff --git a/scheduler/org.cups.cups-lpd.plist.in b/scheduler/org.cups.cups-lpd.plist.in index 76eb2eefd..0866b1555 100644 --- a/scheduler/org.cups.cups-lpd.plist.in +++ b/scheduler/org.cups.cups-lpd.plist.in @@ -7,7 +7,7 @@ Label org.cups.cups-lpd ProcessType - Background + Adaptive EnableTransactions EnablePressuredExit diff --git a/scheduler/org.cups.cupsd.plist b/scheduler/org.cups.cupsd.plist index abc91333c..8e1d0e96e 100644 --- a/scheduler/org.cups.cupsd.plist +++ b/scheduler/org.cups.cupsd.plist @@ -1,11 +1,11 @@ - + Label org.cups.cupsd ProcessType - Background + Adaptive EnableTransactions EnablePressuredExit @@ -25,7 +25,6 @@ /usr/sbin/cupsd -l - EnvironmentVariables CUPS_DEBUG_LOG diff --git a/scheduler/server.c b/scheduler/server.c index 04b26d64d..d28cd4a0b 100644 --- a/scheduler/server.c +++ b/scheduler/server.c @@ -1,7 +1,7 @@ /* * Server start/stop routines for the CUPS scheduler. * - * Copyright 2007-2012 by Apple Inc. + * Copyright 2007-2017 by Apple Inc. * Copyright 1997-2006 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the @@ -78,7 +78,7 @@ cupsdStartServer(void) CUPSD_EVENT_SERVER_STARTED; started = 1; - cupsdSetBusyState(); + cupsdSetBusyState(0); } diff --git a/scheduler/sysman.c b/scheduler/sysman.c index 8b43975d6..46eb39a0b 100644 --- a/scheduler/sysman.c +++ b/scheduler/sysman.c @@ -1,7 +1,7 @@ /* * System management functions for the CUPS scheduler. * - * Copyright 2007-2014 by Apple Inc. + * Copyright 2007-2017 by Apple Inc. * Copyright 2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -75,7 +75,7 @@ cupsdCleanDirty(void) DirtyFiles = CUPSD_DIRTY_NONE; DirtyCleanTime = 0; - cupsdSetBusyState(); + cupsdSetBusyState(0); } @@ -101,7 +101,7 @@ cupsdMarkDirty(int what) /* I - What file(s) are dirty? */ if (!DirtyCleanTime) DirtyCleanTime = time(NULL) + DirtyCleanInterval; - cupsdSetBusyState(); + cupsdSetBusyState(0); } @@ -110,7 +110,7 @@ cupsdMarkDirty(int what) /* I - What file(s) are dirty? */ */ void -cupsdSetBusyState(void) +cupsdSetBusyState(int working) /* I - Doing significant work? */ { int i; /* Looping var */ cupsd_job_t *job; /* Current job */ @@ -139,7 +139,7 @@ cupsdSetBusyState(void) */ newbusy = (DirtyCleanTime ? 1 : 0) | - (cupsArrayCount(ActiveClients) ? 4 : 0); + ((working || cupsArrayCount(ActiveClients) > 0) ? 4 : 0); for (job = (cupsd_job_t *)cupsArrayFirst(PrintingJobs); job; diff --git a/scheduler/sysman.h b/scheduler/sysman.h index 929ee7358..74c667b0d 100644 --- a/scheduler/sysman.h +++ b/scheduler/sysman.h @@ -1,7 +1,7 @@ /* * System management definitions for the CUPS scheduler. * - * Copyright 2007-2014 by Apple Inc. + * Copyright 2007-2017 by Apple Inc. * Copyright 2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -54,6 +54,6 @@ VAR int SysEventPipes[2] VALUE2(-1,-1); extern void cupsdAllowSleep(void); extern void cupsdCleanDirty(void); extern void cupsdMarkDirty(int what); -extern void cupsdSetBusyState(void); +extern void cupsdSetBusyState(int working); extern void cupsdStartSystemMonitor(void); extern void cupsdStopSystemMonitor(void); -- 2.39.5