]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Dropped "dark wake" support on OS X, which was preventing portables from going
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Thu, 7 Nov 2013 01:20:23 +0000 (01:20 +0000)
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Thu, 7 Nov 2013 01:20:23 +0000 (01:20 +0000)
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 (<rdar://problem/14323704>)

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

14 files changed:
CHANGES.txt
backend/ipp.c
backend/lpd.c
backend/socket.c
backend/usb-darwin.c
config-scripts/cups-common.m4
config.h.in
scheduler/job.c
scheduler/job.h
scheduler/main.c
scheduler/printers.c
scheduler/sysman.c
vcnet/config.h
xcode/config.h

index c69c33de360b3488551e6e20425ff7bc6a91eedf..bbe4479c5d6487cb5acc807f2a43b28ce4ec4771 100644 (file)
@@ -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
+         (<rdar://problem/14323704>)
        - Added support for regular expression matching in the MIME type rules
          (<rdar://problem/11131245>)
        - Dropped support for AIX, HP-UX, and OSF/1 (aka Digital UNIX)
index fb9700b110440f7a8dc7ac7f0e323df5bbda72c7..3f202427e1df63405b44e613b3e4b5d25024d12d 100644 (file)
@@ -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;)
index 37fa5a1d2b821b431199dcc0852a0e6dc008c40c..8400ecd9dd0896e0c20f58b2409b09e4bb09836b 100644 (file)
@@ -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...
     */
index ebed1361b476f6c5d220e32be9496f6d00629128..bf70b40a6903816f20bdc6043592729ec1613eaa 100644 (file)
@@ -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)
   {
    /*
index 937d18e1a5768dded4e751b45b68e40b5481d609..2359d9360b4b2686728d059a63cd6f8f6fa22141 100644 (file)
@@ -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;
index 042c26e8e36630f2440d628769afc8c2f96760ab..52e995011a65bdad43d3e0ba4d4106ff6d135ea8 100644 (file)
@@ -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)
index ffb9a2de3c851b6a8fdef71ab0cf10b99d60e10d..f08ea4a5b6d8dc302093c83daa2215e60d136abc 100644 (file)
 #undef HAVE_NOTIFY_POST
 
 
-/*
- * Do we have Darwin's IOKit private headers?
- */
-
-#undef HAVE_IOKIT_PWR_MGT_IOPMLIBPRIVATE_H
-
-
 /*
  * Do we have DBUS?
  */
index fead107a029c586513dd7213aff3d9503cde882e..1d1a0fae13de58a4242f34b85cdb97cbf3e9f7d2 100644 (file)
@@ -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
index f8527f956e1e744d07ce1cc868577366c1ccf389..64e725a9ccdc2bb118077a8053ed05169763122d 100644 (file)
@@ -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 */
index 365ea67d6573ede24b1945d36fdda9384fa65ff9..f9ce3c9b897fb2e6fe8b5af230f932a911509c3b 100644 (file)
@@ -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/".
  */
 
 /*
index e1539406cc2c4d0eceebd5acc8b55aaaf16e760b..b9bb4e86463cfeb22b2e3c08af801856f40bc199 100644 (file)
@@ -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);
       }
index b55b6c9764d8d5c082d3ee4822bacb647bfa1dfd..9235ef9edcf795dd9ef1ed0320d44e9ce84fea6d 100644 (file)
@@ -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/".
  */
 
 
 #endif /* HAVE_VPROC_TRANSACTION_BEGIN */
 #ifdef __APPLE__
 #  include <IOKit/pwr_mgt/IOPMLib.h>
-#  ifdef HAVE_IOKIT_PWR_MGT_IOPMLIBPRIVATE_H
-#    include <IOKit/pwr_mgt/IOPMLibPrivate.h>
-#  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.
  * 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__ */
 
index f4ea5a7af83a2095c0b907aaaf1123cd62e1c0cd..b4ed189138a6b4b7e3490502d873be7c9d8c95a3 100644 (file)
 /* #undef HAVE_NOTIFY_POST */
 
 
-/*
- * Do we have Darwin's IOKit private headers?
- */
-
-/* #undef HAVE_IOKIT_PWR_MGT_IOPMLIBPRIVATE_H */
-
-
 /*
  * Do we have DBUS?
  */
index 2a4e197d73949ea16c2b04d35afd0a7a6333acfe..43a895432bf5231f50cda2703bf25b74242b7398 100644 (file)
 #define HAVE_NOTIFY_POST 1
 
 
-/*
- * Do we have Darwin's IOKit private headers?
- */
-
-/* #undef HAVE_IOKIT_PWR_MGT_IOPMLIBPRIVATE_H */
-
-
 /*
  * Do we have DBUS?
  */