]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/main.c
Dropped "dark wake" support on OS X, which was preventing portables from going
[thirdparty/cups.git] / scheduler / main.c
index afb6e2e6287377b02590c96a31cb7ca8fe2c67a9..f9ce3c9b897fb2e6fe8b5af230f932a911509c3b 100644 (file)
@@ -1,39 +1,16 @@
 /*
- * "$Id: main.c 7925 2008-09-10 17:47:26Z mike $"
+ * "$Id$"
  *
- *   Main loop for the CUPS scheduler.
+ * Main loop for the CUPS scheduler.
  *
- *   Copyright 2007-2012 by Apple Inc.
- *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
+ * Copyright 2007-2013 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
- *   These coded instructions, statements, and computer programs are the
- *   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, see the license at "http://www.cups.org/".
- *
- * Contents:
- *
- *   main()                - Main entry for the CUPS scheduler.
- *   cupsdAddString()      - Copy and add a string to an array.
- *   cupsdCheckProcess()   - Tell the main loop to check for dead children.
- *   cupsdClearString()    - Clear a string.
- *   cupsdFreeStrings()    - Free an array of strings.
- *   cupsdHoldSignals()    - Hold child and termination signals.
- *   cupsdReleaseSignals() - Release signals for delivery.
- *   cupsdSetString()      - Set a string value.
- *   cupsdSetStringf()     - Set a formatted string value.
- *   launchd_checkin()     - Check-in with launchd and collect the listening
- *                           fds.
- *   launchd_checkout()    - Update the launchd KeepAlive file as needed.
- *   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.
- *   usage()               - Show scheduler usage.
+ * These coded instructions, statements, and computer programs are the
+ * 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, see the license at "http://www.cups.org/".
  */
 
 /*
 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
 #  include <malloc.h>
 #endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
+
 #ifdef HAVE_NOTIFY_H
 #  include <notify.h>
 #endif /* HAVE_NOTIFY_H */
 
+#ifdef HAVE_SYS_PARAM_H
+#  include <sys/param.h>
+#endif /* HAVE_SYS_PARAM_H */
+
 
 /*
  * Local functions...
@@ -129,10 +111,6 @@ main(int  argc,                            /* I - Number of command-line args */
 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
   struct sigaction     action;         /* Actions for POSIX signals */
 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
-#ifdef __sgi
-  cups_file_t          *fp;            /* Fake lpsched lock file */
-  struct stat          statbuf;        /* Needed for checking lpsched FIFO */
-#endif /* __sgi */
   int                  run_as_child = 0;
                                        /* Needed for background fork/exec */
 #ifdef __APPLE__
@@ -207,7 +185,6 @@ main(int  argc,                             /* I - Number of command-line args */
 
                 char *current;         /* Current directory */
 
-
               /*
                * Allocate a buffer for the current working directory to
                * reduce run-time stack usage; this approximates the
@@ -271,6 +248,29 @@ main(int  argc,                            /* I - Number of command-line args */
              UseProfiles = 0;
              break;
 
+          case 's' : /* Set cups-files.conf location */
+              i ++;
+             if (i >= argc)
+             {
+               _cupsLangPuts(stderr, _("cupsd: Expected cups-files.conf "
+                                       "filename after \"-s\" option."));
+               usage(1);
+             }
+
+              if (argv[i][0] != '/')
+             {
+              /*
+               * Relative filename not allowed...
+               */
+
+               _cupsLangPuts(stderr, _("cupsd: Relative cups-files.conf "
+                                       "filename not allowed."));
+               usage(1);
+              }
+
+             cupsdSetString(&CupsFilesFile, argv[i]);
+             break;
+
 #ifdef __APPLE__
           case 'S' : /* Disable system management functions */
               fputs("cupsd: -S (disable system management) for internal "
@@ -300,6 +300,35 @@ main(int  argc,                            /* I - Number of command-line args */
   if (!ConfigurationFile)
     cupsdSetString(&ConfigurationFile, CUPS_SERVERROOT "/cupsd.conf");
 
+  if (!CupsFilesFile)
+  {
+    char       *filename,              /* Copy of cupsd.conf filename */
+               *slash;                 /* Final slash in cupsd.conf filename */
+    size_t     len;                    /* Size of buffer */
+
+    len = strlen(ConfigurationFile) + 15;
+    if ((filename = malloc(len)) == NULL)
+    {
+      _cupsLangPrintf(stderr,
+                     _("cupsd: Unable to get path to "
+                       "cups-files.conf file."));
+      return (1);
+    }
+
+    strlcpy(filename, ConfigurationFile, len);
+    if ((slash = strrchr(filename, '/')) == NULL)
+    {
+      _cupsLangPrintf(stderr,
+                     _("cupsd: Unable to get path to "
+                       "cups-files.conf file."));
+      return (1);
+    }
+
+    strlcpy(slash, "/cups-files.conf", len - (slash - filename));
+    cupsdSetString(&CupsFilesFile, filename);
+    free(filename);
+  }
+
  /*
   * If the user hasn't specified "-f", run in the background...
   */
@@ -365,15 +394,15 @@ main(int  argc,                           /* I - Number of command-line args */
       }
     }
 
-#ifdef __OpenBSD__
+#if defined(__OpenBSD__) && OpenBSD < 201211
    /*
     * Call _thread_sys_closefrom() so the child process doesn't reset the
     * parent's file descriptors to be blocking.  This is a workaround for a
-    * limitation of userland libpthread on OpenBSD.
+    * limitation of userland libpthread on older versions of OpenBSD.
     */
 
     _thread_sys_closefrom(0);
-#endif /* __OpenBSD__ */
+#endif /* __OpenBSD__ && OpenBSD < 201211 */
 
    /*
     * Since CoreFoundation and DBUS both create fork-unsafe data on execution of
@@ -483,17 +512,11 @@ main(int  argc,                           /* I - Number of command-line args */
   */
 
   if (!cupsdReadConfiguration())
-  {
-    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);
+    printf("\"%s\" is OK.\n", CupsFilesFile);
+    printf("\"%s\" is OK.\n", ConfigurationFile);
     return (0);
   }
 
@@ -565,28 +588,6 @@ main(int  argc,                            /* I - Number of command-line args */
   signal(SIGTERM, sigterm_handler);
 #endif /* HAVE_SIGSET */
 
-#ifdef __sgi
- /*
-  * Try to create a fake lpsched lock file if one is not already there.
-  * Some Adobe applications need it under IRIX in order to enable
-  * printing...
-  */
-
-  if ((fp = cupsFileOpen("/var/spool/lp/SCHEDLOCK", "w")) == NULL)
-  {
-    syslog(LOG_LPR, "Unable to create fake lpsched lock file "
-                    "\"/var/spool/lp/SCHEDLOCK\"\' - %s!",
-           strerror(errno));
-  }
-  else
-  {
-    fchmod(cupsFileNumber(fp), 0644);
-    fchown(cupsFileNumber(fp), User, Group);
-
-    cupsFileClose(fp);
-  }
-#endif /* __sgi */
-
  /*
   * Initialize authentication certificates...
   */
@@ -679,10 +680,10 @@ main(int  argc,                           /* I - Number of command-line args */
        for (con = (cupsd_client_t *)cupsArrayFirst(Clients);
             con;
             con = (cupsd_client_t *)cupsArrayNext(Clients))
-         if (con->http.state == HTTP_WAITING)
+         if (httpGetState(con->http) == HTTP_WAITING)
            cupsdCloseClient(con);
          else
-           con->http.keep_alive = HTTP_KEEPALIVE_OFF;
+           con->http->keep_alive = HTTP_KEEPALIVE_OFF;
 
         cupsdPauseListening();
       }
@@ -801,7 +802,7 @@ main(int  argc,                             /* I - Number of command-line args */
           i ++, con = (cupsd_client_t *)cupsArrayNext(Clients))
         cupsdLogMessage(CUPSD_LOG_EMERG,
                        "Clients[%d] = %d, file = %d, state = %d",
-                       i, con->http.fd, con->file, con->http.state);
+                       i, con->number, con->file, httpGetState(con->http));
 
       for (i = 0, lis = (cupsd_listener_t *)cupsArrayFirst(Listeners);
            lis;
@@ -922,7 +923,7 @@ main(int  argc,                             /* I - Number of command-line args */
       */
 
       cupsdDeleteCert(0);
-      cupsdAddCert(0, "root", NULL);
+      cupsdAddCert(0, "root", cupsdDefaultAuthType());
     }
 #endif /* !HAVE_AUTHORIZATION_H */
 
@@ -938,7 +939,8 @@ main(int  argc,                             /* I - Number of command-line args */
       * Process pending data in the input buffer...
       */
 
-      if (con->http.used)
+      // TODO: Use httpGetReady()
+      if (con->http->used)
       {
         cupsdReadClient(con);
        continue;
@@ -948,12 +950,13 @@ main(int  argc,                           /* I - Number of command-line args */
       * Check the activity and close old clients...
       */
 
+      // TODO: Use httpGetActivity()
       activity = current_time - Timeout;
-      if (con->http.activity < activity && !con->pipe_pid)
+      if (con->http->activity < activity && !con->pipe_pid)
       {
         cupsdLogMessage(CUPSD_LOG_DEBUG,
                        "Closing client %d after %d seconds of inactivity...",
-                       con->http.fd, Timeout);
+                       con->number, Timeout);
 
         cupsdCloseClient(con);
         continue;
@@ -1114,35 +1117,6 @@ main(int  argc,                          /* I - Number of command-line args */
     cupsdStopSystemMonitor();
 #endif /* __APPLE__ */
 
-#ifdef HAVE_GSSAPI
- /*
-  * Free the scheduler's Kerberos context...
-  */
-
-#  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__ */
-  if (KerberosContext)
-    krb5_free_context(KerberosContext);
-#endif /* HAVE_GSSAPI */
-
-#ifdef __sgi
- /*
-  * Remove the fake IRIX lpsched lock file, but only if the existing
-  * file is not a FIFO which indicates that the real IRIX lpsched is
-  * running...
-  */
-
-  if (!stat("/var/spool/lp/FIFO", &statbuf))
-    if (!S_ISFIFO(statbuf.st_mode))
-      unlink("/var/spool/lp/SCHEDLOCK");
-#endif /* __sgi */
-
   cupsdStopSelect();
 
   return (!stop_scheduler);
@@ -1290,7 +1264,7 @@ cupsdSetStringf(char       **s,           /* O - New string */
                 const char *f,         /* I - Printf-style format string */
                ...)                    /* I - Additional args as needed */
 {
-  char         v[4096];                /* Formatting string value */
+  char         v[65536 + 64];          /* Formatting string value */
   va_list      ap;                     /* Argument pointer */
   char         *olds;                  /* Old string */
 
@@ -1457,7 +1431,7 @@ launchd_checkin(void)
        lis->fd = fd;
 
 #  ifdef HAVE_SSL
-       if (_httpAddrPort(&(lis->address)) == 443)
+       if (httpAddrPort(&(lis->address)) == 443)
          lis->encryption = HTTP_ENCRYPT_ALWAYS;
 #  endif /* HAVE_SSL */
       }
@@ -1781,10 +1755,11 @@ select_timeout(int fds)                 /* I - Number of descriptors returned */
   * processed; if so, the timeout should be 0...
   */
 
+  // TODO: Use httpGetReady()
   for (con = (cupsd_client_t *)cupsArrayFirst(Clients);
        con;
        con = (cupsd_client_t *)cupsArrayNext(Clients))
-    if (con->http.used > 0)
+    if (con->http->used > 0)
       return (0);
 
  /*
@@ -1835,12 +1810,13 @@ select_timeout(int fds)                 /* I - Number of descriptors returned */
   * Check the activity and close old clients...
   */
 
+  // TODO: Use httpGetActivity()
   for (con = (cupsd_client_t *)cupsArrayFirst(Clients);
        con;
        con = (cupsd_client_t *)cupsArrayNext(Clients))
-    if ((con->http.activity + Timeout) < timeout)
+    if ((con->http->activity + Timeout) < timeout)
     {
-      timeout = con->http.activity + Timeout;
+      timeout = con->http->activity + Timeout;
       why     = "timeout a client connection";
     }
 
@@ -2030,5 +2006,5 @@ usage(int status)                 /* O - Exit status */
 
 
 /*
- * End of "$Id: main.c 7925 2008-09-10 17:47:26Z mike $".
+ * End of "$Id$".
  */