]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
scheduler: Fix cupsd activated on-demand via socket
authorZdenek Dohnal <zdohnal@redhat.com>
Tue, 18 Jun 2024 08:43:30 +0000 (10:43 +0200)
committerZdenek Dohnal <zdohnal@redhat.com>
Tue, 18 Jun 2024 08:43:30 +0000 (10:43 +0200)
If only the expected cups.sock is set as listener in cupsd.conf, the
array Listeners was NULL. To prevent copying the code, do the array
allocation earlier and have only one check for Listeners, in
service_checkin() which is run every time cupsd starts.

Fixes #985

scheduler/conf.c
scheduler/main.c

index 88593db3e63d3ba52243093b54444477ad293ba6..afa087d5ef484a87169395fe3f95829373a33e45 100644 (file)
@@ -551,6 +551,18 @@ cupsdReadConfiguration(void)
 
   cupsdDeleteAllListeners();
 
+ /*
+  * Allocate array Listeners
+  */
+
+  Listeners = cupsArrayNew(NULL, NULL);
+
+  if (!Listeners)
+  {
+    fprintf(stderr, "Unable to allocate memory for array Listeners.");
+    return (0);
+  }
+
   old_remote_port = RemotePort;
   RemotePort      = 0;
 
@@ -1043,32 +1055,6 @@ cupsdReadConfiguration(void)
     }
   }
 
- /*
-  * Check that we have at least one listen/port line; if not, report this
-  * as an error and exit!
-  */
-
-#ifdef HAVE_ONDEMAND
-  if (cupsArrayCount(Listeners) == 0 && !OnDemand)
-#else
-  if (cupsArrayCount(Listeners) == 0)
-#endif // HAVE_ONDEMAND
-  {
-   /*
-    * No listeners!
-    */
-
-    cupsdLogMessage(CUPSD_LOG_EMERG,
-                    "No valid Listen or Port lines were found in the "
-                   "configuration file.");
-
-   /*
-    * Commit suicide...
-    */
-
-    cupsdEndProcess(getpid(), 0);
-  }
-
  /*
   * Set the default locale using the language and charset...
   */
@@ -3224,17 +3210,6 @@ read_cupsd_conf(cups_file_t *fp) /* I - File to read from */
         * Allocate another listener...
        */
 
-        if (!Listeners)
-         Listeners = cupsArrayNew(NULL, NULL);
-
-       if (!Listeners)
-       {
-          cupsdLogMessage(CUPSD_LOG_ERROR,
-                         "Unable to allocate %s at line %d - %s.",
-                         line, linenum, strerror(errno));
-          break;
-       }
-
         if ((lis = calloc(1, sizeof(cupsd_listener_t))) == NULL)
        {
           cupsdLogMessage(CUPSD_LOG_ERROR,
index 1c37c840e9a9c99a3ac3ff6ff6ca6b2bec4b321a..5a63829d2b380a6137025761a559efe5cee0d837 100644 (file)
@@ -1977,7 +1977,7 @@ service_checkin(void)
     * No listeners!
     */
 
-    cupsdLogMessage(CUPSD_LOG_EMERG, "service_checkin: No listener sockets present.");
+    cupsdLogMessage(CUPSD_LOG_EMERG, "No listener sockets present.");
 
    /*
     * Commit suicide...