]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/main.c
Import CUPS 1.4svn r7023 into easysw/current.
[thirdparty/cups.git] / scheduler / main.c
index fc15de1f0ab4fc307cd4fca355007b2435b5bd91..9cb8439bbe4c663ca79d4d0c94a00a920a01b69a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: main.c 6689 2007-07-18 23:52:15Z mike $"
+ * "$Id: main.c 6914 2007-09-05 21:05:04Z mike $"
  *
  *   Scheduler main loop for the Common UNIX Printing System (CUPS).
  *
@@ -152,6 +152,18 @@ main(int  argc,                            /* I - Number of command-line args */
 #endif /* HAVE_LAUNCHD */
 
 
+#ifdef HAVE_GETEUID
+ /*
+  * Check for setuid invocation, which we do not support!
+  */
+
+  if (getuid() != geteuid())
+  {
+    fputs("cupsd: Cannot run as a setuid program!\n", stderr);
+    return (1);
+  }
+#endif /* HAVE_GETEUID */
+
  /*
   * Check for command-line arguments...
   */
@@ -242,6 +254,11 @@ main(int  argc,                            /* I - Number of command-line args */
              fg             = 1;
              break;
 
+          case 't' : /* Test the cupsd.conf file... */
+             TestConfigFile = 1;
+             fg             = 1;
+             break;
+
          default : /* Unknown option */
               _cupsLangPrintf(stderr, _("cupsd: Unknown option \"%c\" - "
                                        "aborting!\n"), *opt);
@@ -398,10 +415,18 @@ main(int  argc,                           /* I - Number of command-line args */
 
   if (!cupsdReadConfiguration())
   {
-    syslog(LOG_LPR, "Unable to read configuration file \'%s\' - exiting!",
-           ConfigurationFile);
+    if (TestConfigFile)
+      printf("%s contains errors\n", ConfigurationFile);
+    else
+      syslog(LOG_LPR, "Unable to read configuration file \'%s\' - exiting!",
+            ConfigurationFile);
     return (1);
   }
+  else if (TestConfigFile)
+  {
+    printf("%s is OK\n", ConfigurationFile);
+    return (0);
+  }
 
   if (!strncmp(TempDir, RequestRoot, strlen(RequestRoot)))
   {
@@ -462,6 +487,24 @@ main(int  argc,                            /* I - Number of command-line args */
     PSQUpdateQuotaProc = dlsym(PSQLibRef, PSQLibFuncName);
 #endif /* __APPLE__ && HAVE_DLFCN_H */
 
+#ifdef HAVE_GSSAPI
+#  ifdef __APPLE__
+ /*
+  * If the weak-linked GSSAPI/Kerberos library is not present, don't try
+  * to use it...
+  */
+
+  if (krb5_init_context != NULL)
+#  endif /* __APPLE__ */
+
+ /*
+  * Setup a Kerberos context for the scheduler to use...
+  */
+
+  if (krb5_init_context(&KerberosContext))
+    cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to initialize Kerberos context");
+#endif /* HAVE_GSSAPI */
+
  /*
   * Startup the server...
   */
@@ -783,6 +826,14 @@ main(int  argc,                            /* I - Number of command-line args */
     }
 #endif /* HAVE_LAUNCHD */
 
+   /*
+    * Resume listening for new connections as needed...
+    */
+
+    if (ListeningPaused && ListeningPaused <= current_time &&
+        cupsArrayCount(Clients) < MaxClients)
+      cupsdResumeListening();
+
    /*
     * Expire subscriptions and unload completed jobs as needed...
     */
@@ -960,25 +1011,49 @@ main(int  argc,                          /* I - Number of command-line args */
                     "Scheduler shutting down due to program error.");
 
  /*
-  * Close all network clients and stop all jobs...
+  * Close all network clients...
   */
 
   cupsdStopServer();
 
+#ifdef HAVE_LAUNCHD
+ /*
+  * Update the launchd KeepAlive file as needed...
+  */
+
+  if (Launchd)
+    launchd_checkout();
+#endif /* HAVE_LAUNCHD */
+
+ /*
+  * Stop all jobs...
+  */
+
   cupsdFreeAllJobs();
 
 #ifdef __APPLE__
+ /*
+  * Stop monitoring system event monitoring...
+  */
+
   cupsdStopSystemMonitor();
 #endif /* __APPLE__ */
 
-#ifdef HAVE_LAUNCHD
+#ifdef HAVE_GSSAPI
  /*
-  * Update the launchd KeepAlive file as needed...
+  * Free the scheduler's Kerberos context...
   */
 
-  if (Launchd)
-    launchd_checkout();
-#endif /* HAVE_LAUNCHD */
+#  ifdef __APPLE__
+ /*
+  * If the weak-linked GSSAPI/Kerberos library is not present, don't try
+  * to use it...
+  */
+
+  if (krb5_init_context != NULL)
+#  endif /* __APPLE__ */
+  krb5_free_context(KerberosContext);
+#endif /* HAVE_GSSAPI */
 
 #ifdef __APPLE__
 #ifdef HAVE_DLFCN_H
@@ -1665,6 +1740,21 @@ select_timeout(int fds)                  /* I - Number of descriptors returned */
   timeout = now + 86400;               /* 86400 == 1 day */
   why     = "do nothing";
 
+ /*
+  * Check whether we are accepting new connections...
+  */
+
+  if (ListeningPaused > 0 && cupsArrayCount(Clients) < MaxClients &&
+      ListeningPaused < timeout)
+  {
+    if (ListeningPaused <= now)
+      timeout = now;
+    else
+      timeout = ListeningPaused;
+
+    why = "resume listening";
+  }
+
  /*
   * Check the activity and close old clients...
   */
@@ -1815,5 +1905,5 @@ usage(int status)                 /* O - Exit status */
 
 
 /*
- * End of "$Id: main.c 6689 2007-07-18 23:52:15Z mike $".
+ * End of "$Id: main.c 6914 2007-09-05 21:05:04Z mike $".
  */