]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/main.c
Merge changes from CUPS 1.4svn-r8115.
[thirdparty/cups.git] / scheduler / main.c
index 41d6d197752456b6b7677dd2ae90f009b2d9739e..6f9902441d8f17ffe09fc9fe85f5c504e11e6789 100644 (file)
  *   launchd_checkout()        - Check-out with launchd.
  *   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.
- *   select_timeout()          - Calculate the select timeout value.
  *   usage()                   - Show scheduler usage.
  */
 
@@ -873,6 +873,20 @@ main(int  argc,                            /* I - Number of command-line args */
     if (DirtyCleanTime && current_time >= DirtyCleanTime)
       cupsdCleanDirty();
 
+#ifdef __APPLE__
+   /*
+    * If we are going to sleep and still have pending jobs, stop them after
+    * a period of time...
+    */
+
+    if (SleepJobs > 0 && current_time >= SleepJobs &&
+        cupsArrayCount(PrintingJobs) > 0)
+    {
+      SleepJobs = 0;
+      cupsdStopAllJobs(0);
+    }
+#endif /* __APPLE__ */
+
 #ifndef __APPLE__
    /*
     * Update the network interfaces once a minute...
@@ -1755,66 +1769,6 @@ process_children(void)
 }
 
 
-/*
- * 'sigchld_handler()' - Handle 'child' signals from old processes.
- */
-
-static void
-sigchld_handler(int sig)               /* I - Signal number */
-{
-  (void)sig;
-
- /*
-  * Flag that we have dead children...
-  */
-
-  dead_children = 1;
-
- /*
-  * Reset the signal handler as needed...
-  */
-
-#if !defined(HAVE_SIGSET) && !defined(HAVE_SIGACTION)
-  signal(SIGCLD, sigchld_handler);
-#endif /* !HAVE_SIGSET && !HAVE_SIGACTION */
-}
-
-
-/*
- * 'sighup_handler()' - Handle 'hangup' signals to reconfigure the scheduler.
- */
-
-static void
-sighup_handler(int sig)                        /* I - Signal number */
-{
-  (void)sig;
-
-  NeedReload = RELOAD_ALL;
-  ReloadTime = time(NULL);
-
-#if !defined(HAVE_SIGSET) && !defined(HAVE_SIGACTION)
-  signal(SIGHUP, sighup_handler);
-#endif /* !HAVE_SIGSET && !HAVE_SIGACTION */
-}
-
-
-/*
- * 'sigterm_handler()' - Handle 'terminate' signals that stop the scheduler.
- */
-
-static void
-sigterm_handler(int sig)               /* I - Signal number */
-{
-  (void)sig;   /* remove compiler warnings... */
-
- /*
-  * Flag that we should stop and return...
-  */
-
-  stop_scheduler = 1;
-}
-
-
 /*
  * 'select_timeout()' - Calculate the select timeout value.
  *
@@ -1860,6 +1814,18 @@ select_timeout(int fds)                  /* I - Number of descriptors returned */
   timeout = now + 86400;               /* 86400 == 1 day */
   why     = "do nothing";
 
+#ifdef __APPLE__
+ /*
+  * When going to sleep, wake up to cancel jobs that don't complete in time.
+  */
+
+  if (SleepJobs > 0 && SleepJobs < timeout)
+  {
+    timeout = SleepJobs;
+    why     = "cancel jobs before sleeping";
+  }
+#endif /* __APPLE__ */
+
  /*
   * Check whether we are accepting new connections...
   */
@@ -2015,6 +1981,66 @@ select_timeout(int fds)                  /* I - Number of descriptors returned */
 }
 
 
+/*
+ * 'sigchld_handler()' - Handle 'child' signals from old processes.
+ */
+
+static void
+sigchld_handler(int sig)               /* I - Signal number */
+{
+  (void)sig;
+
+ /*
+  * Flag that we have dead children...
+  */
+
+  dead_children = 1;
+
+ /*
+  * Reset the signal handler as needed...
+  */
+
+#if !defined(HAVE_SIGSET) && !defined(HAVE_SIGACTION)
+  signal(SIGCLD, sigchld_handler);
+#endif /* !HAVE_SIGSET && !HAVE_SIGACTION */
+}
+
+
+/*
+ * 'sighup_handler()' - Handle 'hangup' signals to reconfigure the scheduler.
+ */
+
+static void
+sighup_handler(int sig)                        /* I - Signal number */
+{
+  (void)sig;
+
+  NeedReload = RELOAD_ALL;
+  ReloadTime = time(NULL);
+
+#if !defined(HAVE_SIGSET) && !defined(HAVE_SIGACTION)
+  signal(SIGHUP, sighup_handler);
+#endif /* !HAVE_SIGSET && !HAVE_SIGACTION */
+}
+
+
+/*
+ * 'sigterm_handler()' - Handle 'terminate' signals that stop the scheduler.
+ */
+
+static void
+sigterm_handler(int sig)               /* I - Signal number */
+{
+  (void)sig;   /* remove compiler warnings... */
+
+ /*
+  * Flag that we should stop and return...
+  */
+
+  stop_scheduler = 1;
+}
+
+
 /*
  * 'usage()' - Show scheduler usage.
  */