/*
- * "$Id: main.c 6514 2007-05-07 18:59:25Z mike $"
+ * "$Id: main.c 6914 2007-09-05 21:05:04Z mike $"
*
* Scheduler main loop for the Common UNIX Printing System (CUPS).
*
+ * Copyright 2007 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
- * property of Easy Software Products and are protected by Federal
- * copyright law. Distribution and use rights are outlined in the file
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
* "LICENSE" which should have been included with this file. If this
- * file is missing or damaged please contact Easy Software Products
- * at:
- *
- * Attn: CUPS Licensing Information
- * Easy Software Products
- * 44141 Airport View Drive, Suite 204
- * Hollywood, Maryland 20636 USA
- *
- * Voice: (301) 373-9600
- * EMail: cups-info@cups.org
- * WWW: http://www.cups.org
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
* Contents:
*
#include <sys/resource.h>
#include <syslog.h>
#include <grp.h>
+#include <cups/dir.h>
#ifdef HAVE_LAUNCH_H
# include <launch.h>
#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...
*/
fg = 0;
+#ifdef HAVE_LAUNCHD
+ if (getenv("CUPSD_LAUNCHD"))
+ {
+ Launchd = 1;
+ fg = 1;
+ }
+#endif /* HAVE_LAUNCHD */
+
for (i = 1; i < argc; i ++)
if (argv[i][0] == '-')
for (opt = argv[i] + 1; *opt != '\0'; opt ++)
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);
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)))
+ {
+ /*
+ * Clean out the temporary directory...
+ */
+
+ cups_dir_t *dir; /* Temporary directory */
+ cups_dentry_t *dent; /* Directory entry */
+ char tempfile[1024]; /* Temporary filename */
+
+
+ if ((dir = cupsDirOpen(TempDir)) != NULL)
+ {
+ cupsdLogMessage(CUPSD_LOG_INFO,
+ "Cleaning out old temporary files in \"%s\"...", TempDir);
+
+ while ((dent = cupsDirRead(dir)) != NULL)
+ {
+ snprintf(tempfile, sizeof(tempfile), "%s/%s", TempDir, dent->filename);
+
+ if (cupsdRemoveFile(tempfile))
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Unable to remove temporary file \"%s\" - %s",
+ tempfile, strerror(errno));
+ else
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "Removed temporary file \"%s\"...",
+ tempfile);
+ }
+
+ cupsDirClose(dir);
+ }
+ else
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Unable to open temporary directory \"%s\" - %s",
+ TempDir, strerror(errno));
+ }
#if HAVE_LAUNCHD
if (Launchd)
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...
*/
*/
if (timeout == 86400 && Launchd && LaunchdTimeout && !NumPolled &&
+ !cupsArrayCount(ActiveJobs) &&
(!Browsing ||
(!BrowseRemoteProtocols &&
(!NumBrowsers || !BrowseLocalProtocols ||
}
#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...
*/
"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
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...
*/
/*
- * End of "$Id: main.c 6514 2007-05-07 18:59:25Z mike $".
+ * End of "$Id: main.c 6914 2007-09-05 21:05:04Z mike $".
*/