From: msweet Date: Thu, 7 Nov 2013 01:20:23 +0000 (+0000) Subject: Dropped "dark wake" support on OS X, which was preventing portables from going X-Git-Tag: v2.2b1~814 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=581dae2da052286aae0e5e558d31454894853f56;p=thirdparty%2Fcups.git Dropped "dark wake" support on OS X, which was preventing portables from going to sleep when there was a stuck job. We now use a variation of the CUPS 1.4 sleep support to do a cleaner sleep () Aside from removing all of the power assertions, we now track a new "cups-waiting-for-completed" state keyword that tells cupsd it can SIGKILL a backend without side-effects - then if we are just waiting for the job to complete we can go to sleep immediately. git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@11403 a1ca3aef-8c08-0410-bb20-df032aa958be --- diff --git a/CHANGES.txt b/CHANGES.txt index c69c33de36..bbe4479c5d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,8 +1,12 @@ -CHANGES.txt - 2.0b1 - 2013-10-18 +CHANGES.txt - 2.0b1 - 2013-11-06 -------------------------------- CHANGES IN CUPS V2.0b1 + - Dropped "dark wake" support on OS X, which was preventing portables + from going to sleep when there was a stuck job. We now use a variation + of the CUPS 1.4 sleep support to do a cleaner sleep + () - Added support for regular expression matching in the MIME type rules () - Dropped support for AIX, HP-UX, and OSF/1 (aka Digital UNIX) diff --git a/backend/ipp.c b/backend/ipp.c index fb9700b110..3f202427e1 100644 --- a/backend/ipp.c +++ b/backend/ipp.c @@ -1855,6 +1855,8 @@ main(int argc, /* I - Number of command-line args */ if (!job_id || !waitjob || !get_job_attrs) continue; + fputs("STATE: +cups-waiting-for-completed\n", stderr); + _cupsLangPrintFilter(stderr, "INFO", _("Waiting for job to complete.")); for (delay = _cupsNextDelay(0, &prev_delay); !job_canceled;) diff --git a/backend/lpd.c b/backend/lpd.c index 37fa5a1d2b..8400ecd9dd 100644 --- a/backend/lpd.c +++ b/backend/lpd.c @@ -1,27 +1,18 @@ /* * "$Id$" * - * Line Printer Daemon backend for CUPS. + * Line Printer Daemon backend for CUPS. * - * Copyright 2007-2012 by Apple Inc. - * Copyright 1997-2007 by Easy Software Products, all rights reserved. + * Copyright 2007-2013 by Apple Inc. + * Copyright 1997-2007 by Easy Software Products, all rights reserved. * - * These coded instructions, statements, and computer programs are the - * property of Apple Inc. and are protected by Federal copyright - * law. Distribution and use rights are outlined in the file "LICENSE.txt" - * "LICENSE" which should have been included with this file. If this - * file is missing or damaged, see the license at "http://www.cups.org/". + * These coded instructions, statements, and computer programs are the + * property of Apple Inc. and are protected by Federal copyright + * law. Distribution and use rights are outlined in the file "LICENSE.txt" + * "LICENSE" which should have been included with this file. If this + * file is missing or damaged, see the license at "http://www.cups.org/". * - * This file is subject to the Apple OS-Developed Software exception. - * - * Contents: - * - * main() - Send a file to the printer or server. - * lpd_command() - Send an LPR command sequence and wait for a reply. - * lpd_queue() - Queue a file using the Line Printer Daemon protocol. - * lpd_write() - Write a buffer of data to an LPD server. - * rresvport_af() - A simple implementation of rresvport_af(). - * sigterm_handler() - Handle 'terminate' signals that stop the backend. + * This file is subject to the Apple OS-Developed Software exception. */ /* @@ -1169,6 +1160,8 @@ lpd_queue(const char *hostname, /* I - Host to connect to */ _("Control file sent successfully.")); } + fputs("STATE: +cups-waiting-for-completed\n", stderr); + /* * Collect the final supply levels as needed... */ diff --git a/backend/socket.c b/backend/socket.c index ebed1361b4..bf70b40a69 100644 --- a/backend/socket.c +++ b/backend/socket.c @@ -1,23 +1,18 @@ /* * "$Id$" * - * AppSocket backend for CUPS. + * AppSocket backend for CUPS. * - * Copyright 2007-2012 by Apple Inc. - * Copyright 1997-2007 by Easy Software Products, all rights reserved. + * Copyright 2007-2013 by Apple Inc. + * Copyright 1997-2007 by Easy Software Products, all rights reserved. * - * These coded instructions, statements, and computer programs are the - * property of Apple Inc. and are protected by Federal copyright - * law. Distribution and use rights are outlined in the file "LICENSE.txt" - * "LICENSE" which should have been included with this file. If this - * file is missing or damaged, see the license at "http://www.cups.org/". + * These coded instructions, statements, and computer programs are the + * property of Apple Inc. and are protected by Federal copyright + * law. Distribution and use rights are outlined in the file "LICENSE.txt" + * "LICENSE" which should have been included with this file. If this + * file is missing or damaged, see the license at "http://www.cups.org/". * - * This file is subject to the Apple OS-Developed Software exception. - * - * Contents: - * - * main() - Send a file to the printer or server. - * wait_bc() - Wait for back-channel data... + * This file is subject to the Apple OS-Developed Software exception. */ /* @@ -434,6 +429,8 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ _cupsLangPrintFilter(stderr, "INFO", _("Print file sent.")); } + fputs("STATE: +cups-waiting-for-completed\n", stderr); + if (waiteof) { /* diff --git a/backend/usb-darwin.c b/backend/usb-darwin.c index 937d18e1a5..2359d9360b 100644 --- a/backend/usb-darwin.c +++ b/backend/usb-darwin.c @@ -1,75 +1,46 @@ /* -* "$Id$" -* -* Copyright 2005-2013 Apple Inc. All rights reserved. -* -* IMPORTANT: This Apple software is supplied to you by Apple Computer, -* Inc. ("Apple") in consideration of your agreement to the following -* terms, and your use, installation, modification or redistribution of -* this Apple software constitutes acceptance of these terms. If you do -* not agree with these terms, please do not use, install, modify or -* redistribute this Apple software. -* -* In consideration of your agreement to abide by the following terms, and -* subject to these terms, Apple grants you a personal, non-exclusive -* license, under Apple's copyrights in this original Apple software (the -* "Apple Software"), to use, reproduce, modify and redistribute the Apple -* Software, with or without modifications, in source and/or binary forms; -* provided that if you redistribute the Apple Software in its entirety and -* without modifications, you must retain this notice and the following -* text and disclaimers in all such redistributions of the Apple Software. -* Neither the name, trademarks, service marks or logos of Apple Computer, -* Inc. may be used to endorse or promote products derived from the Apple -* Software without specific prior written permission from Apple. Except -* as expressly stated in this notice, no other rights or licenses, express -* or implied, are granted by Apple herein, including but not limited to -* any patent rights that may be infringed by your derivative works or by -* other works in which the Apple Software may be incorporated. -* -* The Apple Software is provided by Apple on an "AS IS" basis. APPLE -* MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION -* THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS -* FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND -* OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. -* -* IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL -* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -* INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, -* MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED -* AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), -* STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -* -* Contents: -* - * list_devices() - List all USB devices. - * print_device() - Print a file to a USB device. - * read_thread() - Thread to read the backchannel data on. - * sidechannel_thread() - Handle side-channel requests. - * iterate_printers() - Iterate over all the printers. - * device_added() - Device added notifier. - * list_device_cb() - list_device iterator callback. - * find_device_cb() - print_device iterator callback. - * status_timer_cb() - Status timer callback. - * copy_deviceinfo() - Copy strings from the 1284 device ID. - * release_deviceinfo() - Release deviceinfo strings. - * load_classdriver() - Load a classdriver. - * unload_classdriver() - Unload a classdriver. - * load_printerdriver() - Load vendor's classdriver. - * registry_open() - Open a connection to the printer. - * registry_close() - Close the connection to the printer. - * copy_deviceid() - Copy the 1284 device id string. - * copy_devicestring() - Copy the 1284 device id string. - * copy_value_for_key() - Copy value string associated with a key. - * cfstr_create_trim() - Create CFString and trim whitespace characters. - * parse_options() - Parse URI options. - * sigterm_handler() - SIGTERM handler. - * next_line() - Find the next line in a buffer. - * parse_pserror() - Scan the backchannel data for postscript errors. - * soft_reset() - Send a soft reset to the device. - * get_device_id() - Return IEEE-1284 device ID. -*/ + * "$Id$" + * + * Copyright 2005-2013 Apple Inc. All rights reserved. + * + * IMPORTANT: This Apple software is supplied to you by Apple Computer, + * Inc. ("Apple") in consideration of your agreement to the following + * terms, and your use, installation, modification or redistribution of + * this Apple software constitutes acceptance of these terms. If you do + * not agree with these terms, please do not use, install, modify or + * redistribute this Apple software. + * + * In consideration of your agreement to abide by the following terms, and + * subject to these terms, Apple grants you a personal, non-exclusive + * license, under Apple's copyrights in this original Apple software (the + * "Apple Software"), to use, reproduce, modify and redistribute the Apple + * Software, with or without modifications, in source and/or binary forms; + * provided that if you redistribute the Apple Software in its entirety and + * without modifications, you must retain this notice and the following + * text and disclaimers in all such redistributions of the Apple Software. + * Neither the name, trademarks, service marks or logos of Apple Computer, + * Inc. may be used to endorse or promote products derived from the Apple + * Software without specific prior written permission from Apple. Except + * as expressly stated in this notice, no other rights or licenses, express + * or implied, are granted by Apple herein, including but not limited to + * any patent rights that may be infringed by your derivative works or by + * other works in which the Apple Software may be incorporated. + * + * The Apple Software is provided by Apple on an "AS IS" basis. APPLE + * MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION + * THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND + * OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. + * + * IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, + * MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED + * AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), + * STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ /* * Include necessary headers. @@ -790,6 +761,7 @@ print_device(const char *uri, /* I - Device URI */ } fprintf(stderr, "DEBUG: Sent %lld bytes...\n", (off_t)total_bytes); + fputs("STATE: +cups-waiting-for-completed\n", stderr); /* * Signal the side channel thread to exit... @@ -1607,7 +1579,7 @@ static OSStatus copy_deviceid(classdriver_t **classdriver, CFStringRef deviceMake = NULL; CFStringRef deviceModel = NULL; CFStringRef deviceSerial = NULL; - + *deviceID = NULL; OSStatus err = (*classdriver)->GetDeviceID(classdriver, &devID, DEFAULT_TIMEOUT); @@ -1682,13 +1654,13 @@ static OSStatus copy_deviceid(classdriver_t **classdriver, CFRange range = (deviceSerial != NULL ? CFStringFind(deviceSerial, CFSTR("+"), 0) : CFRangeMake(0, 0)); if (range.length == 1) { range = CFStringFind(*deviceID, deviceSerial, 0); - + CFMutableStringRef deviceIDString = CFStringCreateMutableCopy(NULL, 0, *deviceID); CFStringFindAndReplace(deviceIDString, CFSTR("+"), CFSTR(""), range, 0); CFRelease(*deviceID); *deviceID = deviceIDString; } - + release_deviceinfo(&deviceMake, &deviceModel, &deviceSerial); return err; diff --git a/config-scripts/cups-common.m4 b/config-scripts/cups-common.m4 index 042c26e8e3..52e995011a 100644 --- a/config-scripts/cups-common.m4 +++ b/config-scripts/cups-common.m4 @@ -354,7 +354,6 @@ case $uname in AC_CHECK_HEADER(CoreFoundation/CoreFoundation.h,AC_DEFINE(HAVE_COREFOUNDATION_H)) AC_CHECK_HEADER(CoreFoundation/CFPriv.h,AC_DEFINE(HAVE_CFPRIV_H)) AC_CHECK_HEADER(CoreFoundation/CFBundlePriv.h,AC_DEFINE(HAVE_CFBUNDLEPRIV_H)) - AC_CHECK_HEADER(IOKit/pwr_mgt/IOPMLibPrivate.h,AC_DEFINE(HAVE_IOKIT_PWR_MGT_IOPMLIBPRIVATE_H)) dnl Check for dynamic store function... AC_CHECK_FUNCS(SCDynamicStoreCopyComputerName) diff --git a/config.h.in b/config.h.in index ffb9a2de3c..f08ea4a5b6 100644 --- a/config.h.in +++ b/config.h.in @@ -515,13 +515,6 @@ #undef HAVE_NOTIFY_POST -/* - * Do we have Darwin's IOKit private headers? - */ - -#undef HAVE_IOKIT_PWR_MGT_IOPMLIBPRIVATE_H - - /* * Do we have DBUS? */ diff --git a/scheduler/job.c b/scheduler/job.c index fead107a02..1d1a0fae13 100644 --- a/scheduler/job.c +++ b/scheduler/job.c @@ -257,7 +257,8 @@ cupsdCheckJobs(void) if (job->kill_time && job->kill_time <= curtime) { - cupsdLogJob(job, CUPSD_LOG_ERROR, "Stopping unresponsive job."); + if (!job->completed) + cupsdLogJob(job, CUPSD_LOG_ERROR, "Stopping unresponsive job."); stop_job(job, CUPSD_JOB_FORCE); continue; @@ -269,8 +270,12 @@ cupsdCheckJobs(void) if (job->cancel_time && job->cancel_time <= curtime) { - cupsdSetJobState(job, IPP_JOB_CANCELED, CUPSD_JOB_DEFAULT, - "Canceling stuck job after %d seconds.", MaxJobTime); + if (job->completed) + cupsdSetJobState(job, IPP_JOB_CANCELED, CUPSD_JOB_FORCE, + "Marking stuck job as completed after %d seconds.", MaxJobTime); + else + cupsdSetJobState(job, IPP_JOB_CANCELED, CUPSD_JOB_DEFAULT, + "Canceling stuck job after %d seconds.", MaxJobTime); continue; } @@ -323,10 +328,7 @@ cupsdCheckJobs(void) */ if (job->state_value == IPP_JOB_PENDING && !NeedReload && -#ifndef kIOPMAssertionTypeDenySystemSleep - !Sleeping && -#endif /* !kIOPMAssertionTypeDenySystemSleep */ - !DoingShutdown && !job->printer) + !Sleeping && !DoingShutdown && !job->printer) { printer = cupsdFindDest(job->dest); pclass = NULL; @@ -2645,10 +2647,17 @@ cupsdStopAllJobs( job; job = (cupsd_job_t *)cupsArrayNext(PrintingJobs)) { - if (kill_delay) - job->kill_time = time(NULL) + kill_delay; + if (job->completed) + { + cupsdSetJobState(job, IPP_JOB_COMPLETED, CUPSD_JOB_FORCE, NULL); + } + else + { + if (kill_delay) + job->kill_time = time(NULL) + kill_delay; - cupsdSetJobState(job, IPP_JOB_PENDING, action, NULL); + cupsdSetJobState(job, IPP_JOB_PENDING, action, NULL); + } } } @@ -2924,11 +2933,13 @@ finalize_job(cupsd_job_t *job, /* I - Job */ cupsdLogMessage(CUPSD_LOG_DEBUG2, "finalize_job(job=%p(%d))", job, job->id); /* - * Clear the "connecting-to-device" reason, which is only valid when a printer - * is processing, along with any remote printing job state... + * Clear the "connecting-to-device" and "cups-waiting-for-completed" reasons, + * which are only valid when a printer is processing, along with any remote + * printing job state... */ cupsdSetPrinterReasons(job->printer, "-connecting-to-device," + "cups-waiting-for-completed," "cups-remote-pending," "cups-remote-pending-held," "cups-remote-processing," @@ -4768,17 +4779,17 @@ update_job(cupsd_job_t *job) /* I - Job to check */ * Reset cancel time after connecting to the device... */ - ipp_attribute_t *cancel_after = ippFindAttribute(job->attrs, - "job-cancel-after", - IPP_TAG_INTEGER); - /* job-cancel-after attribute */ - for (i = 0; i < job->printer->num_reasons; i ++) if (!strcmp(job->printer->reasons[i], "connecting-to-device")) break; if (i >= job->printer->num_reasons) { + ipp_attribute_t *cancel_after = ippFindAttribute(job->attrs, + "job-cancel-after", + IPP_TAG_INTEGER); + /* job-cancel-after attribute */ + if (cancel_after) job->cancel_time = time(NULL) + ippGetInteger(cancel_after, 0); else diff --git a/scheduler/job.h b/scheduler/job.h index f8527f956e..64e725a9cc 100644 --- a/scheduler/job.h +++ b/scheduler/job.h @@ -1,16 +1,16 @@ /* * "$Id$" * - * Print job definitions for the CUPS scheduler. + * Print job definitions for the CUPS scheduler. * - * Copyright 2007-2011 by Apple Inc. - * Copyright 1997-2007 by Easy Software Products, all rights reserved. + * Copyright 2007-2013 by Apple Inc. + * Copyright 1997-2007 by Easy Software Products, all rights reserved. * - * These coded instructions, statements, and computer programs are the - * property of Apple Inc. and are protected by Federal copyright - * law. Distribution and use rights are outlined in the file "LICENSE.txt" - * which should have been included with this file. If this file is - * file is missing or damaged, see the license at "http://www.cups.org/". + * These coded instructions, statements, and computer programs are the + * property of Apple Inc. and are protected by Federal copyright + * law. Distribution and use rights are outlined in the file "LICENSE.txt" + * which should have been included with this file. If this file is + * file is missing or damaged, see the license at "http://www.cups.org/". */ /* @@ -74,6 +74,7 @@ struct cupsd_job_s /**** Job request ****/ int backend; /* Backend process ID */ int status; /* Status code from filters */ int tries; /* Number of tries for this job */ + int completed; /* cups-waiting-for-completed seen */ char *auth_env[3], /* AUTH_xxx environment variables, * if any */ *auth_uid; /* AUTH_UID environment variable */ diff --git a/scheduler/main.c b/scheduler/main.c index 365ea67d65..f9ce3c9b89 100644 --- a/scheduler/main.c +++ b/scheduler/main.c @@ -1,39 +1,16 @@ /* * "$Id$" * - * Main loop for the CUPS scheduler. + * Main loop for the CUPS scheduler. * - * Copyright 2007-2012 by Apple Inc. - * Copyright 1997-2007 by Easy Software Products, all rights reserved. + * Copyright 2007-2013 by Apple Inc. + * Copyright 1997-2007 by Easy Software Products, all rights reserved. * - * These coded instructions, statements, and computer programs are the - * property of Apple Inc. and are protected by Federal copyright - * law. Distribution and use rights are outlined in the file "LICENSE.txt" - * "LICENSE" which should have been included with this file. If this - * file is missing or damaged, see the license at "http://www.cups.org/". - * - * Contents: - * - * main() - Main entry for the CUPS scheduler. - * cupsdAddString() - Copy and add a string to an array. - * cupsdCheckProcess() - Tell the main loop to check for dead children. - * cupsdClearString() - Clear a string. - * cupsdFreeStrings() - Free an array of strings. - * cupsdHoldSignals() - Hold child and termination signals. - * cupsdReleaseSignals() - Release signals for delivery. - * cupsdSetString() - Set a string value. - * cupsdSetStringf() - Set a formatted string value. - * launchd_checkin() - Check-in with launchd and collect the listening - * fds. - * launchd_checkout() - Update the launchd KeepAlive file as needed. - * parent_handler() - Catch USR1/CHLD signals... - * process_children() - Process all dead children... - * select_timeout() - Calculate the select timeout value. - * sigchld_handler() - Handle 'child' signals from old processes. - * sighup_handler() - Handle 'hangup' signals to reconfigure the - * scheduler. - * sigterm_handler() - Handle 'terminate' signals that stop the scheduler. - * usage() - Show scheduler usage. + * These coded instructions, statements, and computer programs are the + * property of Apple Inc. and are protected by Federal copyright + * law. Distribution and use rights are outlined in the file "LICENSE.txt" + * "LICENSE" which should have been included with this file. If this + * file is missing or damaged, see the license at "http://www.cups.org/". */ /* diff --git a/scheduler/printers.c b/scheduler/printers.c index e1539406cc..b9bb4e8646 100644 --- a/scheduler/printers.c +++ b/scheduler/printers.c @@ -2471,8 +2471,12 @@ cupsdSetPrinterReasons( if (!strcmp(reason, "paused") && p->state == IPP_PRINTER_STOPPED) cupsdSetPrinterState(p, IPP_PRINTER_IDLE, 1); + if (!strcmp(reason, "cups-waiting-for-completed") && p->job) + p->job->completed = 0; + if (strcmp(reason, "connecting-to-device")) dirty_printer(p); + break; } } @@ -2507,6 +2511,9 @@ cupsdSetPrinterReasons( if (!strcmp(reason, "paused") && p->state != IPP_PRINTER_STOPPED) cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, 1); + if (!strcmp(reason, "cups-waiting-for-completed") && p->job) + p->job->completed = 1; + if (strcmp(reason, "connecting-to-device")) dirty_printer(p); } diff --git a/scheduler/sysman.c b/scheduler/sysman.c index b55b6c9764..9235ef9edc 100644 --- a/scheduler/sysman.c +++ b/scheduler/sysman.c @@ -1,34 +1,16 @@ /* * "$Id$" * - * System management functions for the CUPS scheduler. + * System management functions for the CUPS scheduler. * - * Copyright 2007-2013 by Apple Inc. - * Copyright 2006 by Easy Software Products. + * Copyright 2007-2013 by Apple Inc. + * Copyright 2006 by Easy Software Products. * - * These coded instructions, statements, and computer programs are the - * property of Apple Inc. and are protected by Federal copyright - * law. Distribution and use rights are outlined in the file "LICENSE.txt" - * which should have been included with this file. If this file is - * file is missing or damaged, see the license at "http://www.cups.org/". - * - * Contents: - * - * cupsdCleanDirty() - Write dirty config and state files. - * cupsdMarkDirty() - Mark config or state files as needing a - * write. - * cupsdSetBusyState() - Let the system know when we are busy - * doing something. - * cupsdAllowSleep() - Tell the OS it is now OK to sleep. - * cupsdStartSystemMonitor() - Start monitoring for system change. - * cupsdStopSystemMonitor() - Stop monitoring for system change. - * sysEventThreadEntry() - A thread to receive power and computer - * name change notifications. - * sysEventPowerNotifier() - Handle power notification events. - * sysEventConfigurationNotifier() - Computer name changed notification - * callback. - * sysEventTimerNotifier() - Handle delayed event notifications. - * sysUpdate() - Update the current system state. + * These coded instructions, statements, and computer programs are the + * property of Apple Inc. and are protected by Federal copyright + * law. Distribution and use rights are outlined in the file "LICENSE.txt" + * which should have been included with this file. If this file is + * file is missing or damaged, see the license at "http://www.cups.org/". */ @@ -42,11 +24,6 @@ #endif /* HAVE_VPROC_TRANSACTION_BEGIN */ #ifdef __APPLE__ # include -# ifdef HAVE_IOKIT_PWR_MGT_IOPMLIBPRIVATE_H -# include -# else -# define kIOPMAssertionTypeDenySystemSleep CFSTR("DenySystemSleep") -# endif /* HAVE_IOKIT_PWR_MGT_IOPMLIBPRIVATE_H */ #endif /* __APPLE__ */ @@ -58,7 +35,7 @@ * and state files to minimize the number of times the disk has to spin * up. * - * Power management support is currently only implemented on MacOS X, but + * Power management support is currently only implemented on OS X, but * essentially we use four functions to let the OS know when it is OK to * put the system to sleep, typically when we are not in the middle of * printing a job. @@ -67,15 +44,6 @@ * to wake up in a new location/on a new wireless network. */ -/* - * Local globals... - */ - -#if defined(kIOPMAssertionTypeDenySystemSleep) || defined(kIOPMAssertNetworkClientActive) -static IOPMAssertionID keep_awake = 0; /* Keep the system awake while printing */ -#endif /* kIOPMAssertionTypeDenySystemSleep || kIOPMAssertNetworkClientActive */ - - /* * 'cupsdCleanDirty()' - Write dirty config and state files. */ @@ -216,33 +184,6 @@ cupsdSetBusyState(void) } #endif /* HAVE_VPROC_TRANSACTION_BEGIN */ } - -#if defined(kIOPMAssertionTypeDenySystemSleep) || defined(kIOPMAssertNetworkClientActive) - if (cupsArrayCount(PrintingJobs) > 0 && !keep_awake) - { -# ifdef kIOPMAssertNetworkClientActive - cupsdLogMessage(CUPSD_LOG_DEBUG, "Asserting NetworkClientActive."); - - IOPMAssertionCreateWithName(kIOPMAssertNetworkClientActive, - kIOPMAssertionLevelOn, - CFSTR("org.cups.cupsd"), &keep_awake); - -# else - cupsdLogMessage(CUPSD_LOG_DEBUG, "Asserting DenySystemSleep."); - - IOPMAssertionCreateWithName(kIOPMAssertionTypeDenySystemSleep, - kIOPMAssertionLevelOn, - CFSTR("org.cups.cupsd"), &keep_awake); - -# endif /* kIOPMAssertNetworkClientActive */ - } - else if (cupsArrayCount(PrintingJobs) == 0 && keep_awake) - { - cupsdLogMessage(CUPSD_LOG_DEBUG, "Releasing power assertion."); - IOPMAssertionRelease(keep_awake); - keep_awake = 0; - } -#endif /* kIOPMAssertionTypeDenySystemSleep || kIOPMAssertNetworkClientActive */ } @@ -323,6 +264,7 @@ static CFStringRef ComputerNameKey = NULL, NetworkInterfaceKeyIPv6 = NULL; /* Netowrk interface key */ static cupsd_sysevent_t LastSysEvent; /* Last system event (for delayed sleep) */ +static int NameChanged = 0;/* Did we get a 'name changed' event during sleep? */ /* @@ -338,6 +280,7 @@ static void sysEventConfigurationNotifier(SCDynamicStoreRef store, void *context); static void sysEventTimerNotifier(CFRunLoopTimerRef timer, void *context); static void sysUpdate(void); +static void sysUpdateNames(void); /* @@ -681,6 +624,7 @@ sysEventPowerNotifier( case kIOMessageSystemWillPowerOff : case kIOMessageSystemWillSleep : threadData->sysevent.event |= SYSEVENT_WILLSLEEP; + threadData->sysevent.event &= ~SYSEVENT_WOKE; break; case kIOMessageSystemHasPoweredOn : @@ -876,8 +820,9 @@ sysUpdate(void) { /* * If there are active printers that don't have the connecting-to-device - * printer-state-reason then cancel the sleep request (i.e. this reason - * indicates a job that is not yet connected to the printer)... + * or cups-waiting-for-completed printer-state-reason then cancel the sleep + * request, i.e., these reasons indicate a job that is not actively doing + * anything... */ for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); @@ -887,7 +832,8 @@ sysUpdate(void) if (p->job) { for (i = 0; i < p->num_reasons; i ++) - if (!strcmp(p->reasons[i], "connecting-to-device")) + if (!strcmp(p->reasons[i], "connecting-to-device") || + !strcmp(p->reasons[i], "cups-waiting-for-completed")) break; if (!p->num_reasons || i >= p->num_reasons) @@ -898,14 +844,14 @@ sysUpdate(void) if (p) { cupsdLogMessage(CUPSD_LOG_INFO, - "System sleep canceled because printer %s is active", + "System sleep canceled because printer %s is active.", p->name); IOCancelPowerChange(sysevent.powerKernelPort, sysevent.powerNotificationID); } else { - cupsdLogMessage(CUPSD_LOG_DEBUG, "System wants to sleep"); + cupsdLogMessage(CUPSD_LOG_DEBUG, "System wants to sleep."); IOAllowPowerChange(sysevent.powerKernelPort, sysevent.powerNotificationID); } @@ -913,38 +859,15 @@ sysUpdate(void) if (sysevent.event & SYSEVENT_WILLSLEEP) { - cupsdLogMessage(CUPSD_LOG_DEBUG, "System going to sleep"); + cupsdLogMessage(CUPSD_LOG_DEBUG, "System going to sleep."); Sleeping = 1; - for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); - p; - p = (cupsd_printer_t *)cupsArrayNext(Printers)) - { - cupsdLogMessage(CUPSD_LOG_DEBUG, - "Deregistering local printer \"%s\"", p->name); - cupsdDeregisterPrinter(p, 0); - } - cupsdCleanDirty(); -#ifdef kIOPMAssertionTypeDenySystemSleep - /* - * Remove our assertion as needed since the user wants the system to - * sleep (different than idle sleep)... - */ - - if (keep_awake) - { - cupsdLogMessage(CUPSD_LOG_DEBUG, "Releasing dark wake assertion."); - IOPMAssertionRelease(keep_awake); - keep_awake = 0; - } -#endif /* kIOPMAssertionTypeDenySystemSleep */ - /* * If we have no printing jobs, allow the power change immediately. - * Otherwise set the SleepJobs time to 15 seconds in the future when + * Otherwise set the SleepJobs time to 10 seconds in the future when * we'll take more drastic measures... */ @@ -958,8 +881,8 @@ sysUpdate(void) { /* * If there are active printers that don't have the connecting-to-device - * printer-state-reason then delay the sleep request (i.e. this reason - * indicates a job that is not yet connected to the printer)... + * or cups-waiting-for-completed printer-state-reasons then delay the + * sleep request, i.e., these reasons indicate a job is active... */ for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); @@ -969,7 +892,8 @@ sysUpdate(void) if (p->job) { for (i = 0; i < p->num_reasons; i ++) - if (!strcmp(p->reasons[i], "connecting-to-device")) + if (!strcmp(p->reasons[i], "connecting-to-device") || + !strcmp(p->reasons[i], "cups-waiting-for-completed")) break; if (!p->num_reasons || i >= p->num_reasons) @@ -979,6 +903,10 @@ sysUpdate(void) if (p) { + cupsdLogMessage(CUPSD_LOG_INFO, + "System sleep delayed because printer %s is active.", + p->name); + LastSysEvent = sysevent; SleepJobs = time(NULL) + 10; } @@ -993,21 +921,11 @@ sysUpdate(void) if (sysevent.event & SYSEVENT_WOKE) { - cupsdLogMessage(CUPSD_LOG_DEBUG, "System woke from sleep"); + cupsdLogMessage(CUPSD_LOG_DEBUG, "System woke from sleep."); IOAllowPowerChange(sysevent.powerKernelPort, sysevent.powerNotificationID); Sleeping = 0; -#ifdef kIOPMAssertionTypeDenySystemSleep - if (cupsArrayCount(PrintingJobs) > 0 && !keep_awake) - { - cupsdLogMessage(CUPSD_LOG_DEBUG, "Asserting dark wake."); - IOPMAssertionCreateWithName(kIOPMAssertionTypeDenySystemSleep, - kIOPMAssertionLevelOn, - CFSTR("org.cups.cupsd"), &keep_awake); - } -#endif /* kIOPMAssertionTypeDenySystemSleep */ - /* * Make sure jobs that were queued prior to the system going to sleep don't * get canceled right away... @@ -1035,59 +953,82 @@ sysUpdate(void) } } + if (NameChanged) + sysUpdateNames(); + cupsdCheckJobs(); } if (sysevent.event & SYSEVENT_NETCHANGED) { - if (!Sleeping) + if (Sleeping) cupsdLogMessage(CUPSD_LOG_DEBUG, - "System network configuration changed"); + "System network configuration changed - " + "ignored while sleeping."); else cupsdLogMessage(CUPSD_LOG_DEBUG, - "System network configuration changed; " - "ignored while sleeping"); + "System network configuration changed."); } if (sysevent.event & SYSEVENT_NAMECHANGED) { - if (!Sleeping) + if (Sleeping) + { + NameChanged = 1; + + cupsdLogMessage(CUPSD_LOG_DEBUG, + "Computer name or BTMM domains changed - ignored while " + "sleeping."); + } + else { cupsdLogMessage(CUPSD_LOG_DEBUG, - "Computer name or BTMM domains changed"); + "Computer name or BTMM domains changed."); - /* - * De-register the individual printers... - */ + sysUpdateNames(); + } + } + } +} - for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); - p; - p = (cupsd_printer_t *)cupsArrayNext(Printers)) - cupsdDeregisterPrinter(p, 1); + +/* + * 'sysUpdateNames()' - Update computer and/or BTMM domains. + */ + +static void +sysUpdateNames(void) +{ + cupsd_printer_t *p; /* Current printer */ + + + NameChanged = 0; + + /* + * De-register the individual printers... + */ + + for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); + p; + p = (cupsd_printer_t *)cupsArrayNext(Printers)) + cupsdDeregisterPrinter(p, 1); # if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) - /* - * Update the computer name and BTMM domain list... - */ + /* + * Update the computer name and BTMM domain list... + */ - cupsdUpdateDNSSDName(); + cupsdUpdateDNSSDName(); # endif /* HAVE_DNSSD || HAVE_AVAHI */ - /* - * Now re-register them... - */ + /* + * Now re-register them... + */ - for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); - p; - p = (cupsd_printer_t *)cupsArrayNext(Printers)) - cupsdRegisterPrinter(p); - } - else - cupsdLogMessage(CUPSD_LOG_DEBUG, - "Computer name or BTMM domains changed; ignored while " - "sleeping"); - } - } + for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); + p; + p = (cupsd_printer_t *)cupsArrayNext(Printers)) + cupsdRegisterPrinter(p); } #endif /* __APPLE__ */ diff --git a/vcnet/config.h b/vcnet/config.h index f4ea5a7af8..b4ed189138 100644 --- a/vcnet/config.h +++ b/vcnet/config.h @@ -580,13 +580,6 @@ /* #undef HAVE_NOTIFY_POST */ -/* - * Do we have Darwin's IOKit private headers? - */ - -/* #undef HAVE_IOKIT_PWR_MGT_IOPMLIBPRIVATE_H */ - - /* * Do we have DBUS? */ diff --git a/xcode/config.h b/xcode/config.h index 2a4e197d73..43a895432b 100644 --- a/xcode/config.h +++ b/xcode/config.h @@ -515,13 +515,6 @@ #define HAVE_NOTIFY_POST 1 -/* - * Do we have Darwin's IOKit private headers? - */ - -/* #undef HAVE_IOKIT_PWR_MGT_IOPMLIBPRIVATE_H */ - - /* * Do we have DBUS? */