]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/main.c
Merge pull request #5621 from zdohnal/cgigetarray-sigsegv
[thirdparty/cups.git] / scheduler / main.c
index 3b258a70ab0ce4b6d9e9116c1771b407aac489d9..d5fdf971a8acee0ac51bf9e5f353828c4ae3f2bc 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Main loop for the CUPS scheduler.
  *
- * Copyright © 2007-2018 by Apple Inc.
+ * Copyright © 2007-2019 by Apple Inc.
  * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
  *
  * Licensed under Apache License v2.0.  See the file "LICENSE" for more
@@ -345,6 +345,7 @@ main(int  argc,                             /* I - Number of command-line args */
     strlcpy(filename, ConfigurationFile, len);
     if ((slash = strrchr(filename, '/')) == NULL)
     {
+      free(filename);
       _cupsLangPrintf(stderr,
                      _("cupsd: Unable to get path to "
                        "cups-files.conf file."));
@@ -755,7 +756,12 @@ main(int  argc,                            /* I - Number of command-line args */
 
 #ifdef HAVE_ONDEMAND
        if (OnDemand)
+       {
+#  ifndef HAVE_SYSTEMD /* Issue #5640: systemd doesn't actually support launch-on-demand services, need to fake it */
+         stop_scheduler = 1;
+#  endif /* HAVE_SYSTEMD */
          break;
+       }
 #endif /* HAVE_ONDEMAND */
 
         DoingShutdown = 1;
@@ -963,8 +969,7 @@ main(int  argc,                             /* I - Number of command-line args */
 
     if (current_time > expire_time)
     {
-      if (cupsArrayCount(Subscriptions) > 0)
-        cupsdExpireSubscriptions(NULL, NULL);
+      cupsdExpireSubscriptions(NULL, NULL);
 
       cupsdUnloadCompletedJobs();
 
@@ -999,6 +1004,23 @@ main(int  argc,                           /* I - Number of command-line args */
     }
 #endif /* !HAVE_AUTHORIZATION_H */
 
+   /*
+    * Clean job history...
+    */
+
+    if (JobHistoryUpdate && current_time >= JobHistoryUpdate)
+      cupsdCleanJobs();
+
+   /*
+    * Update any pending multi-file documents...
+    */
+
+    if ((current_time - senddoc_time) >= 10)
+    {
+      cupsdCheckJobs();
+      senddoc_time = current_time;
+    }
+
    /*
     * Check for new data on the client sockets...
     */
@@ -1031,23 +1053,6 @@ main(int  argc,                          /* I - Number of command-line args */
       }
     }
 
-   /*
-    * Update any pending multi-file documents...
-    */
-
-    if ((current_time - senddoc_time) >= 10)
-    {
-      cupsdCheckJobs();
-      senddoc_time = current_time;
-    }
-
-   /*
-    * Clean job history...
-    */
-
-    if (JobHistoryUpdate && current_time >= JobHistoryUpdate)
-      cupsdCleanJobs();
-
    /*
     * Log statistics at most once a minute when in debug mode...
     */
@@ -1629,7 +1634,6 @@ select_timeout(int fds)                   /* I - Number of descriptors returned */
   time_t               now;            /* Current time */
   cupsd_client_t       *con;           /* Client information */
   cupsd_job_t          *job;           /* Job information */
-  cupsd_printer_t       *printer;       /* Printer information */
   const char           *why;           /* Debugging aid */
 
 
@@ -1718,12 +1722,6 @@ select_timeout(int fds)                  /* I - Number of descriptors returned */
   * Check for any job activity...
   */
 
-  if (JobHistoryUpdate && timeout > JobHistoryUpdate)
-  {
-    timeout = JobHistoryUpdate;
-    why     = "update job history";
-  }
-
   for (job = (cupsd_job_t *)cupsArrayFirst(ActiveJobs);
        job;
        job = (cupsd_job_t *)cupsArrayNext(ActiveJobs))
@@ -1754,22 +1752,6 @@ select_timeout(int fds)                  /* I - Number of descriptors returned */
     }
   }
 
- /*
-  * Check for temporary printers that need to be deleted...
-  */
-
-  for (printer = (cupsd_printer_t *)cupsArrayFirst(Printers); printer; printer = (cupsd_printer_t *)cupsArrayNext(Printers))
-  {
-    if (printer->temporary && !printer->job && (!local_timeout || local_timeout > (printer->state_time + 60)))
-      local_timeout = printer->state_time + 60;
-  }
-
-  if (timeout > local_timeout && local_timeout)
-  {
-    timeout = local_timeout;
-    why     = "delete stale local printers";
-  }
-
  /*
   * Adjust from absolute to relative time.  We add 1 second to the timeout since
   * events occur after the timeout expires, and limit the timeout to 86400
@@ -2071,13 +2053,31 @@ service_checkout(int shutdown)          /* I - Shutting down? */
 #ifdef HAVE_ONDEMAND
   if (OnDemand)
   {
+    int shared_printers = 0;           /* Do we have shared printers? */
+
     strlcpy(pidfile, CUPS_KEEPALIVE, sizeof(pidfile));
 
+   /*
+    * If printer sharing is on see if there are any actual shared printers...
+    */
+
+    if (Browsing && BrowseLocalProtocols)
+    {
+      cupsd_printer_t *p = NULL;       /* Current printer */
+
+      for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); p; p = (cupsd_printer_t *)cupsArrayNext(Printers))
+      {
+        if (p->shared)
+          break;
+      }
+
+      shared_printers = (p != NULL);
+    }
+
     if (cupsArrayCount(ActiveJobs) ||  /* Active jobs */
         WebInterface ||                        /* Web interface enabled */
         NeedReload ||                  /* Doing a reload */
-        (Browsing && BrowseLocalProtocols && cupsArrayCount(Printers)))
-                                        /* Printers being shared */
+        shared_printers)                /* Printers being shared */
     {
      /*
       * Create or remove the "keep-alive" file based on whether there are active