]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Re-introduce dark wake support, but this time while monitoring the current
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Sat, 30 Aug 2014 01:51:22 +0000 (01:51 +0000)
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Sat, 30 Aug 2014 01:51:22 +0000 (01:51 +0000)
power source (<rdar://problem/17325852>)

This allows printing to work while the system is visibly asleep.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@12140 a1ca3aef-8c08-0410-bb20-df032aa958be

CHANGES.txt
config-scripts/cups-common.m4
config.h.in
doc/help/man-ipptool.html
man/ipptool.man
scheduler/job.c
scheduler/main.c
scheduler/sysman.c
scheduler/sysman.h
xcode/config.h

index 57e1e020fe8873ca227c6a932b9a1e1f2ff8e946..e59a94d3e7482b2b2eb0c48eeb20371cd5bcfcb3 100644 (file)
@@ -1,9 +1,11 @@
-CHANGES.txt - 2.0rc1 - 2014-08-28
+CHANGES.txt - 2.0rc1 - 2014-08-29
 ---------------------------------
 
 CHANGES IN CUPS V2.0rc1
 
        - Documentation updates (STR #4464)
+       - The scheduler now monitors the AC power status on OS X, allowing for
+         "sleep printing" when sharing printers (<rdar://problem/17325852>)
        - The scheduler incorrectly called launch_activate_socket multiple times
          on OS X (<rdar://problem/17523218>)
        - The ippserver test program now passes the IPP Everywhere self-
index c01523b979197160a48dbaa31303c06750940ea3..ec98d4eb09ad185f91e6eac4504572f9b4251778 100644 (file)
@@ -369,9 +369,6 @@ case $uname in
                AC_CHECK_HEADER(membershipPriv.h,AC_DEFINE(HAVE_MEMBERSHIPPRIV_H))
                AC_CHECK_FUNCS(mbr_uid_to_uuid)
 
-                dnl Check for the vproc_transaction_begin/end stuff...
-               AC_CHECK_FUNCS(vproc_transaction_begin)
-
                dnl Need <dlfcn.h> header...
                AC_CHECK_HEADER(dlfcn.h,AC_DEFINE(HAVE_DLFCN_H))
 
index a6c62b8e140f19368ab71c0dfa956ad31ff4a2f5..5937ac3c27cfb94ffde8ef057de10a4b8f9bb69b 100644 (file)
 #endif /* HAVE_ARC4RANDOM */
 
 
-/*
- * Do we have vproc_transaction_begin/end?
- */
-
-#undef HAVE_VPROC_TRANSACTION_BEGIN
-
-
 /*
  * Do we have libusb?
  */
index fc6ac1b7028017f3ff34930491b955499af2b073..aba14e5510c5b2ac34292d608f26da54a7570b5d 100644 (file)
@@ -71,9 +71,12 @@ ipptool - perform internet printing protocol requests
 <b>ipptool</b>
 sends IPP requests to the specified
 <i>printer-uri</i>
-and tests and/or displays the results. Each named
+and tests and/or displays the results.
+Each named
 <i>testfile</i>
-defines one or more requests, including the expected response status, attributes, and values. Output is either a plain text, formatted text, CSV, or XML report on the standard output, with a non-zero exit status indicating that one or more tests have failed. The
+defines one or more requests, including the expected response status, attributes, and values.
+Output is either a plain text, formatted text, CSV, or XML report on the standard output, with a non-zero exit status indicating that one or more tests have failed.
+The
 <i>testfile</i>
 format is described in
 <a href="man-ipptoolfile.html?TOPIC=Man+Pages"><b>ipptoolfile</b>(5).</a>
@@ -102,7 +105,8 @@ must connect to the printer or server using IPv4.
 <b>ipptool</b>
 must connect to the printer or server using IPv6.
 <dt><b>-C</b>
-<dd style="margin-left: 5.0em">Specifies that requests should be sent using the HTTP/1.1 "Transfer-Encoding: chunked" header, which is required for conformance by all versions of IPP. The default is to use "Transfer-Encoding: chunked" for requests with attached files and "Content-Length:" for requests without attached files.
+<dd style="margin-left: 5.0em">Specifies that requests should be sent using the HTTP/1.1 "Transfer-Encoding: chunked" header, which is required for conformance by all versions of IPP.
+The default is to use "Transfer-Encoding: chunked" for requests with attached files and "Content-Length:" for requests without attached files.
 <dt><b>-E</b>
 <dd style="margin-left: 5.0em">Forces TLS encryption when connecting to the server using the HTTP "Upgrade" header.
 <dt><b>-I</b>
@@ -110,9 +114,11 @@ must connect to the printer or server using IPv6.
 <b>ipptool</b>
 will continue past errors.
 <dt><b>-L</b>
-<dd style="margin-left: 5.0em">Specifies that requests should be sent using the HTTP/1.0 "Content-Length:" header, which is required for conformance by all versions of IPP. The default is to use "Transfer-Encoding: chunked" for requests with attached files and "Content-Length:" for requests without attached files.
+<dd style="margin-left: 5.0em">Specifies that requests should be sent using the HTTP/1.0 "Content-Length:" header, which is required for conformance by all versions of IPP.
+The default is to use "Transfer-Encoding: chunked" for requests with attached files and "Content-Length:" for requests without attached files.
 <dt><b>-P</b><i> filename.plist</i>
-<dd style="margin-left: 5.0em">Specifies that the test results should be written to the named XML (Apple plist) file in addition to the plain text report. This option is incompatible with the <b>-i</b> (interval) and <b>-n</b> (repeat-count) options.
+<dd style="margin-left: 5.0em">Specifies that the test results should be written to the named XML (Apple plist) file in addition to the regular test report (<b>-t</b>).
+This option is incompatible with the <b>-i</b> (interval) and <b>-n</b> (repeat-count) options.
 <dt><b>-S</b>
 <dd style="margin-left: 5.0em">Forces (dedicated) TLS encryption when connecting to the server.
 <dt><b>-T</b><i> seconds</i>
@@ -120,7 +126,8 @@ will continue past errors.
 <dt><b>-V</b><i> version</i>
 <dd style="margin-left: 5.0em">Specifies the default IPP version to use: 1.0, 1.1, 2.0, 2.1, or 2.2. If not specified, version 1.1 is used.
 <dt><b>-X</b>
-<dd style="margin-left: 5.0em">Specifies that XML (Apple plist) output is desired instead of the plain text report. This option is incompatible with the <b>-i</b> (interval) and <b>-n</b> (repeat-count) options.
+<dd style="margin-left: 5.0em">Specifies that XML (Apple plist) output is desired instead of the plain text report.
+This option is incompatible with the <b>-i</b> (interval) and <b>-n</b> (repeat-count) options.
 <dt><b>-c</b>
 <dd style="margin-left: 5.0em">Specifies that CSV (comma-separated values) output is desired instead of the plain text output.
 <dt><b>-d</b><i> name=value</i>
@@ -130,17 +137,22 @@ will continue past errors.
 <dt><b>-i</b><i> seconds</i>
 <dd style="margin-left: 5.0em">Specifies that the (last)
 <i>testfile</i>
-should be repeated at the specified interval. This option is incompatible with the <b>-X</b> (XML plist output) option.
+should be repeated at the specified interval.
+This option is incompatible with the <b>-X</b> (XML plist output) option.
 <dt><b>-l</b>
 <dd style="margin-left: 5.0em">Specifies that plain text output is desired.
 <dt><b>-n</b><i> repeat-count</i>
 <dd style="margin-left: 5.0em">Specifies that the (last)
 <i>testfile</i>
-should be repeated the specified number of times. This option is incompatible with the <i>-X</i> (XML plist output) option.
+should be repeated the specified number of times.
+This option is incompatible with the <i>-X</i> (XML plist output) option.
+<dt><b>-q</b>
+<dd style="margin-left: 5.0em">Be quiet and produce no output.
 <dt><b>-t</b>
 <dd style="margin-left: 5.0em">Specifies that CUPS test report output is desired instead of the plain text output.
 <dt><b>-v</b>
-<dd style="margin-left: 5.0em">Specifies that all request and response attributes should be output in CUPS test mode (<b>-t</b>). This is the default for XML output.
+<dd style="margin-left: 5.0em">Specifies that all request and response attributes should be output in CUPS test mode (<b>-t</b>).
+This is the default for XML output.
 </dl>
 <h2 class="title"><a name="EXIT_STATUS">Exit Status</a></h2>
 The
index d5397a59dc02de1600944345c7703317529b9197..9fa9f05d452c4442793840b22b707919d9b515a2 100644 (file)
@@ -11,7 +11,7 @@
 .\" 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/".
 .\"
-.TH ipptool 1 "CUPS" "15 May 2014" "Apple Inc."
+.TH ipptool 1 "CUPS" "29 August 2014" "Apple Inc."
 .SH NAME
 ipptool \- perform internet printing protocol requests
 .SH SYNOPSIS
@@ -76,9 +76,12 @@ ipptool \- perform internet printing protocol requests
 .B ipptool
 sends IPP requests to the specified
 .I printer-uri
-and tests and/or displays the results. Each named
+and tests and/or displays the results.
+Each named
 .I testfile
-defines one or more requests, including the expected response status, attributes, and values. Output is either a plain text, formatted text, CSV, or XML report on the standard output, with a non-zero exit status indicating that one or more tests have failed. The
+defines one or more requests, including the expected response status, attributes, and values.
+Output is either a plain text, formatted text, CSV, or XML report on the standard output, with a non-zero exit status indicating that one or more tests have failed.
+The
 .I testfile
 format is described in
 .BR ipptoolfile (5).
@@ -112,7 +115,8 @@ Specifies that
 must connect to the printer or server using IPv6.
 .TP 5
 .B \-C
-Specifies that requests should be sent using the HTTP/1.1 "Transfer\-Encoding: chunked" header, which is required for conformance by all versions of IPP. The default is to use "Transfer\-Encoding: chunked" for requests with attached files and "Content\-Length:" for requests without attached files.
+Specifies that requests should be sent using the HTTP/1.1 "Transfer\-Encoding: chunked" header, which is required for conformance by all versions of IPP.
+The default is to use "Transfer\-Encoding: chunked" for requests with attached files and "Content\-Length:" for requests without attached files.
 .TP 5
 .B \-E
 Forces TLS encryption when connecting to the server using the HTTP "Upgrade" header.
@@ -123,10 +127,12 @@ Specifies that
 will continue past errors.
 .TP 5
 .B \-L
-Specifies that requests should be sent using the HTTP/1.0 "Content\-Length:" header, which is required for conformance by all versions of IPP. The default is to use "Transfer\-Encoding: chunked" for requests with attached files and "Content\-Length:" for requests without attached files.
+Specifies that requests should be sent using the HTTP/1.0 "Content\-Length:" header, which is required for conformance by all versions of IPP.
+The default is to use "Transfer\-Encoding: chunked" for requests with attached files and "Content\-Length:" for requests without attached files.
 .TP 5
 .BI \-P \ filename.plist
-Specifies that the test results should be written to the named XML (Apple plist) file in addition to the plain text report. This option is incompatible with the \fB\-i\fR (interval) and \fB\-n\fR (repeat\-count) options.
+Specifies that the test results should be written to the named XML (Apple plist) file in addition to the regular test report (\fB\-t\fR).
+This option is incompatible with the \fB\-i\fR (interval) and \fB\-n\fR (repeat\-count) options.
 .TP 5
 .B \-S
 Forces (dedicated) TLS encryption when connecting to the server.
@@ -138,7 +144,8 @@ Specifies a timeout for IPP requests in seconds.
 Specifies the default IPP version to use: 1.0, 1.1, 2.0, 2.1, or 2.2. If not specified, version 1.1 is used.
 .TP 5
 .B \-X
-Specifies that XML (Apple plist) output is desired instead of the plain text report. This option is incompatible with the \fB\-i\fR (interval) and \fB\-n\fR (repeat\-count) options.
+Specifies that XML (Apple plist) output is desired instead of the plain text report.
+This option is incompatible with the \fB\-i\fR (interval) and \fB\-n\fR (repeat\-count) options.
 .TP 5
 .B \-c
 Specifies that CSV (comma\-separated values) output is desired instead of the plain text output.
@@ -152,7 +159,8 @@ Defines the default request filename for tests.
 .BI \-i \ seconds
 Specifies that the (last)
 .I testfile
-should be repeated at the specified interval. This option is incompatible with the \fB\-X\fR (XML plist output) option.
+should be repeated at the specified interval.
+This option is incompatible with the \fB\-X\fR (XML plist output) option.
 .TP 5
 .B \-l
 Specifies that plain text output is desired.
@@ -160,13 +168,18 @@ Specifies that plain text output is desired.
 .BI \-n \ repeat\-count
 Specifies that the (last)
 .I testfile
-should be repeated the specified number of times. This option is incompatible with the \fI\-X\fR (XML plist output) option.
+should be repeated the specified number of times.
+This option is incompatible with the \fI\-X\fR (XML plist output) option.
+.TP 5
+.B \-q
+Be quiet and produce no output.
 .TP 5
 .B \-t
 Specifies that CUPS test report output is desired instead of the plain text output.
 .TP 5
 .B \-v
-Specifies that all request and response attributes should be output in CUPS test mode (\fB\-t\fR). This is the default for XML output.
+Specifies that all request and response attributes should be output in CUPS test mode (\fB\-t\fR).
+This is the default for XML output.
 .SH EXIT STATUS
 The
 .B ipptool
index 9d500d1fbf133e11f7d9c11cb76cd83e093fa1d9..0d81570d5c40b2260094d6245a0b6550ec6bf2de 100644 (file)
@@ -235,10 +235,7 @@ cupsdCheckJobs(void)
 
   curtime = time(NULL);
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                  "cupsdCheckJobs: %d active jobs, sleeping=%d, reload=%d, "
-                  "curtime=%ld", cupsArrayCount(ActiveJobs), Sleeping,
-                  NeedReload, (long)curtime);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdCheckJobs: %d active jobs, sleeping=%d, ac-power=%d, reload=%d, curtime=%ld", cupsArrayCount(ActiveJobs), Sleeping, ACPower, NeedReload, (long)curtime);
 
   for (job = (cupsd_job_t *)cupsArrayFirst(ActiveJobs);
        job;
@@ -332,7 +329,7 @@ cupsdCheckJobs(void)
     */
 
     if (job->state_value == IPP_JOB_PENDING && !NeedReload &&
-        !Sleeping && !DoingShutdown && !job->printer)
+        (!Sleeping || ACPower) && !DoingShutdown && !job->printer)
     {
       printer = cupsdFindDest(job->dest);
       pclass  = NULL;
index 48789a1cf9156e5cfcc0af12be3e817107a7091c..259efd78e69926f2864fd4d98b3965c8dffca41a 100644 (file)
@@ -119,8 +119,7 @@ main(int  argc,                             /* I - Number of command-line args */
   int                  run_as_child = 0;
                                        /* Needed for background fork/exec */
 #ifdef __APPLE__
-  int                  use_sysman = !getuid();
-                                       /* Use system management functions? */
+  int                  use_sysman = 1; /* Use system management functions? */
 #else
   time_t               netif_time = 0; /* Time since last network update */
 #endif /* __APPLE__ */
@@ -137,7 +136,7 @@ main(int  argc,                             /* I - Number of command-line args */
 
   if (getuid() != geteuid())
   {
-    fputs("cupsd: Cannot run as a setuid program\n", stderr);
+    fputs("cupsd: Cannot run as a setuid program.\n", stderr);
     return (1);
   }
 #endif /* HAVE_GETEUID */
index 16d10eb87d36e7bf3c85c40c8ef747a4d0bf20d0..404ff9a57f3564fb73e0809a85fb5df206638145 100644 (file)
@@ -3,7 +3,7 @@
  *
  * System management functions for the CUPS scheduler.
  *
- * Copyright 2007-2013 by Apple Inc.
+ * Copyright 2007-2014 by Apple Inc.
  * Copyright 2006 by Easy Software Products.
  *
  * These coded instructions, statements, and computer programs are the
  */
 
 #include "cupsd.h"
-#ifdef HAVE_VPROC_TRANSACTION_BEGIN
-#  include <vproc.h>
-#endif /* HAVE_VPROC_TRANSACTION_BEGIN */
 #ifdef __APPLE__
+#  include <vproc.h>
 #  include <IOKit/pwr_mgt/IOPMLib.h>
 #endif /* __APPLE__ */
 
 
 /*
  * The system management functions cover disk and power management which
- * are primarily used on portable computers.
+ * are primarily used for portable computers.
  *
  * Disk management involves delaying the write of certain configuration
  * and state files to minimize the number of times the disk has to spin
- * up.
+ * up or flash to be written to.
  *
  * 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.
- *
- * Once put to sleep, we invalidate all remote printers since it is common
- * to wake up in a new location/on a new wireless network.
+ * printing a job.  And on OS X we can also "sleep print" - basically the
+ * system only wakes up long enough to service network requests and process
+ * print jobs.
  */
 
+
 /*
  * 'cupsdCleanDirty()' - Write dirty config and state files.
  */
@@ -132,9 +130,10 @@ cupsdSetBusyState(void)
     "Active clients and printing jobs",
     "Active clients, printing jobs, and dirty files"
   };
-#ifdef HAVE_VPROC_TRANSACTION_BEGIN
+#ifdef __APPLE__
   static vproc_transaction_t vtran = 0;        /* Current busy transaction */
-#endif /* HAVE_VPROC_TRANSACTION_BEGIN */
+  static IOPMAssertionID keep_awake = 0;/* Keep the system awake while printing */
+#endif /* __APPLE__ */
 
 
  /*
@@ -174,7 +173,7 @@ cupsdSetBusyState(void)
   {
     busy = newbusy;
 
-#ifdef HAVE_VPROC_TRANSACTION_BEGIN
+#ifdef __APPLE__
     if (busy && !vtran)
       vtran = vproc_transaction_begin(NULL);
     else if (!busy && vtran)
@@ -182,8 +181,25 @@ cupsdSetBusyState(void)
       vproc_transaction_end(NULL, vtran);
       vtran = 0;
     }
-#endif /* HAVE_VPROC_TRANSACTION_BEGIN */
+#endif /* __APPLE__ */
+  }
+
+#ifdef __APPLE__
+  if (cupsArrayCount(PrintingJobs) > 0 && !keep_awake)
+  {
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "Asserting NetworkClientActive.");
+
+    IOPMAssertionCreateWithName(kIOPMAssertNetworkClientActive,
+                               kIOPMAssertionLevelOn,
+                               CFSTR("org.cups.cupsd"), &keep_awake);
   }
+  else if (cupsArrayCount(PrintingJobs) == 0 && keep_awake)
+  {
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "Releasing power assertion.");
+    IOPMAssertionRelease(keep_awake);
+    keep_awake = 0;
+  }
+#endif /* __APPLE__ */
 }
 
 
@@ -198,8 +214,10 @@ cupsdSetBusyState(void)
  * Include MacOS-specific headers...
  */
 
+#  include <notify.h>
 #  include <IOKit/IOKitLib.h>
 #  include <IOKit/IOMessage.h>
+#  include <IOKit/ps/IOPowerSources.h>
 #  include <IOKit/pwr_mgt/IOPMLib.h>
 #  include <SystemConfiguration/SystemConfiguration.h>
 #  include <pthread.h>
@@ -265,6 +283,7 @@ static CFStringRef  ComputerNameKey = 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? */
+static int             PSToken = 0;    /* Power source notifications */
 
 
 /*
@@ -308,6 +327,8 @@ cupsdStartSystemMonitor(void)
   int  flags;                          /* fcntl flags on pipe */
 
 
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdStartSystemMonitor()");
+
   if (cupsdOpenPipe(SysEventPipes))
   {
     cupsdLogMessage(CUPSD_LOG_ERROR, "System event monitor pipe() failed - %s!",
@@ -332,6 +353,14 @@ cupsdStartSystemMonitor(void)
   pthread_mutex_init(&SysEventThreadMutex, NULL);
   pthread_cond_init(&SysEventThreadCond, NULL);
   pthread_create(&SysEventThread, NULL, (void *(*)())sysEventThreadEntry, NULL);
+
+ /*
+  * Monitor for power source changes via dispatch queue...
+  */
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdStartSystemMonitor: IOPSGetTimeRemainingEstimate=%f", IOPSGetTimeRemainingEstimate());
+  ACPower = IOPSGetTimeRemainingEstimate() == kIOPSTimeRemainingUnlimited;
+  notify_register_dispatch(kIOPSNotifyPowerSource, &PSToken, dispatch_get_main_queue(), ^(int t) { ACPower = IOPSGetTimeRemainingEstimate() == kIOPSTimeRemainingUnlimited; });
 }
 
 
@@ -345,6 +374,8 @@ cupsdStopSystemMonitor(void)
   CFRunLoopRef rl;                     /* The event handler runloop */
 
 
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdStopSystemMonitor()");
+
   if (SysEventThread)
   {
    /*
@@ -375,6 +406,12 @@ cupsdStopSystemMonitor(void)
     cupsdRemoveSelect(SysEventPipes[0]);
     cupsdClosePipe(SysEventPipes);
   }
+
+  if (PSToken != 0)
+  {
+    notify_cancel(PSToken);
+    PSToken = 0;
+  }
 }
 
 
index 810b185f0dfde7ad949d2b0fdc9d64df81b55c46..e3497ed0ebd35978d18c947ab96e0556ea2733eb 100644 (file)
@@ -1,16 +1,16 @@
 /*
  * "$Id$"
  *
- *   System management definitions for the CUPS scheduler.
+ * System management definitions for the CUPS scheduler.
  *
- *   Copyright 2007-2011 by Apple Inc.
- *   Copyright 2006 by Easy Software Products.
+ * Copyright 2007-2014 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/".
+ * 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/".
  */
 
 /*
@@ -35,7 +35,9 @@ VAR int                       DirtyFiles      VALUE(CUPSD_DIRTY_NONE),
                                        /* How often do we write dirty files? */
 VAR time_t             DirtyCleanTime  VALUE(0);
                                        /* When to clean dirty files next */
-VAR int                        Sleeping        VALUE(0);
+VAR int                        ACPower         VALUE(-1),
+                                       /* Is the system on AC power? */
+                       Sleeping        VALUE(0);
                                        /* Non-zero if machine is entering or *
                                         * in a sleep state...                */
 VAR time_t             SleepJobs       VALUE(0);
index 94a6f5d8534c4e08c16615a213836f5fd690816b..89e2b0b1040d4c011c2a66cbd1e14fc1c2e0c232 100644 (file)
 #endif /* HAVE_ARC4RANDOM */
 
 
-/*
- * Do we have vproc_transaction_begin/end?
- */
-
-#define HAVE_VPROC_TRANSACTION_BEGIN 1
-
-
 /*
  * Do we have libusb?
  */