]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Allocate fd_sets to support more than 1024 file descriptors...
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 5 Feb 2003 21:10:18 +0000 (21:10 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 5 Feb 2003 21:10:18 +0000 (21:10 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@3321 7a7537e8-13f0-0310-91df-b6672ffda945

CHANGES.txt
scheduler/client.c
scheduler/conf.c
scheduler/cupsd.h
scheduler/dirsvc.c
scheduler/ipp.c
scheduler/job.c
scheduler/listen.c
scheduler/main.c
scheduler/server.c

index 3279790bdf84f7f14f5a35d961fafd492b27375c..7e35c76e713c47988aff05a49fe9b85a5f492a5f 100644 (file)
@@ -1,8 +1,11 @@
-CHANGES.txt - 02/03/2003
+CHANGES.txt - 02/05/2003
 ------------------------
 
 CHANGES IN CUPS V1.1.19
 
+       - The scheduler now allocates its select() sets to
+         support larger numbers of clients on systems that
+         support it.
        - The scheduler now sets the CFProcessPath environment
          variable under MacOS X.
        - The cupsLangDefault() function now uses the
index ef562c77d0b99bbaa973c1a96757b849e27dfeb7..97b3974efa833f512ea0c5fc1118991bdfcf35d7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: client.c,v 1.142 2003/02/03 02:33:42 mike Exp $"
+ * "$Id: client.c,v 1.143 2003/02/05 21:10:15 mike Exp $"
  *
  *   Client routines for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -289,7 +289,7 @@ AcceptClient(listener_t *lis)       /* I - Listener socket */
 
   LogMessage(L_DEBUG2, "AcceptClient: Adding fd %d to InputSet...",
              con->http.fd);
-  FD_SET(con->http.fd, &InputSet);
+  FD_SET(con->http.fd, InputSet);
 
   NumClients ++;
 
@@ -418,8 +418,8 @@ CloseClient(client_t *con)  /* I - Client to close */
     LogMessage(L_DEBUG2, "CloseClient: Removing fd %d from InputSet and OutputSet...",
                con->http.fd);
     close(con->http.fd);
-    FD_CLR(con->http.fd, &InputSet);
-    FD_CLR(con->http.fd, &OutputSet);
+    FD_CLR(con->http.fd, InputSet);
+    FD_CLR(con->http.fd, OutputSet);
     con->http.fd = 0;
   }
 
@@ -427,7 +427,7 @@ CloseClient(client_t *con)  /* I - Client to close */
   {
     LogMessage(L_DEBUG2, "CloseClient: Removing fd %d from InputSet...",
                con->file);
-    FD_CLR(con->file, &InputSet);
+    FD_CLR(con->file, InputSet);
   }
 
   if (con->file)
@@ -447,7 +447,7 @@ CloseClient(client_t *con)  /* I - Client to close */
     LogMessage(L_DEBUG2, "CloseClient: %d Removing fd %d from InputSet.",
                con->http.fd, con->file);
 
-    FD_CLR(con->file, &InputSet);
+    FD_CLR(con->file, InputSet);
     close(con->file);
     con->file = 0;
   }
@@ -1762,8 +1762,8 @@ SendCommand(client_t      *con,
   LogMessage(L_DEBUG2, "SendCommand: Adding fd %d to OutputSet...",
              con->http.fd);
 
-  FD_SET(con->file, &InputSet);
-  FD_SET(con->http.fd, &OutputSet);
+  FD_SET(con->file, InputSet);
+  FD_SET(con->http.fd, OutputSet);
 
   if (!SendHeader(con, HTTP_OK, NULL))
     return (0);
@@ -1902,7 +1902,7 @@ SendFile(client_t    *con,
 
   LogMessage(L_DEBUG2, "SendFile: Adding fd %d to OutputSet...", con->http.fd);
 
-  FD_SET(con->http.fd, &OutputSet);
+  FD_SET(con->http.fd, OutputSet);
 
   return (1);
 }
@@ -2003,7 +2003,7 @@ ShutdownClient(client_t *con)             /* I - Client connection */
   LogMessage(L_DEBUG2, "ShutdownClient: Removing fd %d from InputSet...",
              con->http.fd);
 
-  FD_CLR(con->http.fd, &InputSet);
+  FD_CLR(con->http.fd, InputSet);
 }
 
 
@@ -2118,13 +2118,13 @@ WriteClient(client_t *con)              /* I - Client connection */
     LogMessage(L_DEBUG2, "WriteClient: Removing fd %d from OutputSet...",
                con->http.fd);
 
-    FD_CLR(con->http.fd, &OutputSet);
+    FD_CLR(con->http.fd, OutputSet);
 
     if (con->file)
     {
       LogMessage(L_DEBUG2, "WriteClient: Removing fd %d from InputSet...",
                  con->file);
-      FD_CLR(con->file, &InputSet);
+      FD_CLR(con->file, InputSet);
 
       if (con->pipe_pid)
        kill(con->pipe_pid, SIGTERM);
@@ -2932,5 +2932,5 @@ CDSAWriteFunc(SSLConnectionRef connection,        /* I  - SSL/TLS connection */
 
 
 /*
- * End of "$Id: client.c,v 1.142 2003/02/03 02:33:42 mike Exp $".
+ * End of "$Id: client.c,v 1.143 2003/02/05 21:10:15 mike Exp $".
  */
index 1511c377071f6be2eecfdd734a0be823e390cedd..b1acedebf9d516d9ce00b7c63866fdf0ec46554b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: conf.c,v 1.123 2003/02/04 19:02:25 mike Exp $"
+ * "$Id: conf.c,v 1.124 2003/02/05 21:10:15 mike Exp $"
  *
  *   Configuration routines for the Common UNIX Printing System (CUPS).
  *
@@ -39,7 +39,6 @@
 #include <stdarg.h>
 #include <pwd.h>
 #include <grp.h>
-#include <sys/resource.h>
 
 #ifdef HAVE_CDSASSL
 #  include <Security/SecureTransport.h>
@@ -197,7 +196,6 @@ ReadConfiguration(void)
                *slash;                 /* Directory separator */
   char         type[MIME_MAX_SUPER + MIME_MAX_TYPE];
                                        /* MIME type name */
-  struct rlimit        limit;                  /* Runtime limit */
   char         *language;              /* Language string */
   struct passwd        *user;                  /* Default user */
   struct group *group;                 /* Default group */
@@ -541,10 +539,14 @@ ReadConfiguration(void)
   * Check the MaxClients setting, and then allocate memory for it...
   */
 
-  getrlimit(RLIMIT_NOFILE, &limit);
+  if (MaxClients > (MaxFDs / 3) || MaxClients <= 0)
+  {
+    if (MaxClients > 0)
+      LogMessage(L_INFO, "MaxClients limited to 1/3 of the file descriptor limit (%d)...",
+                 MaxFDs);
 
-  if (MaxClients > (limit.rlim_max / 3) || MaxClients <= 0)
-    MaxClients = limit.rlim_max / 3;
+    MaxClients = MaxFDs / 3;
+  }
 
   if ((Clients = calloc(sizeof(client_t), MaxClients)) == NULL)
   {
@@ -2047,5 +2049,5 @@ CDSAGetServerCerts(void)
 
 
 /*
- * End of "$Id: conf.c,v 1.123 2003/02/04 19:02:25 mike Exp $".
+ * End of "$Id: conf.c,v 1.124 2003/02/05 21:10:15 mike Exp $".
  */
index 1ca8652040ac956cf35d35bca4177f623f717cda..1b7ad2ed3aab3dfe3b0bec22a5f627cd2afeddd5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: cupsd.h,v 1.41 2003/01/29 19:54:50 mike Exp $"
+ * "$Id: cupsd.h,v 1.42 2003/02/05 21:10:15 mike Exp $"
  *
  *   Main header file for the Common UNIX Printing System (CUPS) scheduler.
  *
  *         WWW: http://www.cups.org
  */
 
+/*
+ * Define FD_SETSIZE to 2048; on platforms that support this, this will
+ * ensure that the correct version of select() is used for large numbers
+ * of file descriptors.
+ */
+
+#define FD_SETSIZE     2048
+
+
 /*
  * Include necessary headers.
  */
@@ -160,9 +169,10 @@ typedef struct direct DIRENT;
  * Globals...
  */
 
-VAR int                        MaxFDs;         /* Maximum number of files */
-VAR fd_set             InputSet,       /* Input files for select() */
-                       OutputSet;      /* Output files for select() */
+VAR int                        MaxFDs,         /* Maximum number of files */
+                       SetSize;        /* The size of the input/output sets */
+VAR fd_set             *InputSet,      /* Input files for select() */
+                       *OutputSet;     /* Output files for select() */
 
 VAR int                        NeedReload      VALUE(TRUE);
                                        /* Need to load configuration? */
@@ -191,5 +201,5 @@ extern void StopServer(void);
 
 
 /*
- * End of "$Id: cupsd.h,v 1.41 2003/01/29 19:54:50 mike Exp $".
+ * End of "$Id: cupsd.h,v 1.42 2003/02/05 21:10:15 mike Exp $".
  */
index d834e8fb4dcc7ab6c657b35a670550fab404f464..e5e6647abce2750ac52e9252a58c8bd7ea6c643c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: dirsvc.c,v 1.107 2003/01/31 01:26:31 mike Exp $"
+ * "$Id: dirsvc.c,v 1.108 2003/02/05 21:10:16 mike Exp $"
  *
  *   Directory services routines for the Common UNIX Printing System (CUPS).
  *
@@ -772,7 +772,7 @@ StartBrowsing(void)
     LogMessage(L_DEBUG2, "StartBrowsing: Adding fd %d to InputSet...",
                BrowseSocket);
 
-    FD_SET(BrowseSocket, &InputSet);
+    FD_SET(BrowseSocket, InputSet);
   }
 
 #ifdef HAVE_LIBSLP
@@ -929,7 +929,7 @@ StartPolling(void)
   LogMessage(L_DEBUG2, "StartPolling: Adding fd %d to InputSet...",
              PollPipe);
 
-  FD_SET(PollPipe, &InputSet);
+  FD_SET(PollPipe, InputSet);
 }
 
 
@@ -960,7 +960,7 @@ StopBrowsing(void)
       LogMessage(L_DEBUG2, "StopBrowsing: Removing fd %d from InputSet...",
                 BrowseSocket);
 
-      FD_CLR(BrowseSocket, &InputSet);
+      FD_CLR(BrowseSocket, InputSet);
       BrowseSocket = 0;
     }
   }
@@ -995,7 +995,7 @@ StopPolling(void)
 
     LogMessage(L_DEBUG2, "StopPolling: removing fd %d from InputSet.",
                PollPipe);
-    FD_CLR(PollPipe, &InputSet);
+    FD_CLR(PollPipe, InputSet);
 
     PollPipe = -1;
   }
@@ -1853,5 +1853,5 @@ UpdateSLPBrowse(void)
 
 
 /*
- * End of "$Id: dirsvc.c,v 1.107 2003/01/31 01:26:31 mike Exp $".
+ * End of "$Id: dirsvc.c,v 1.108 2003/02/05 21:10:16 mike Exp $".
  */
index 24052e28b0a3a0bf6dbcd9a7390a98122c0d2bf3..0d1cc9a6ed02d3f38993bb8696878f84bf629690 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ipp.c,v 1.186 2003/01/31 17:48:23 mike Exp $"
+ * "$Id: ipp.c,v 1.187 2003/02/05 21:10:16 mike Exp $"
  *
  *   IPP routines for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -448,7 +448,7 @@ ProcessIPPRequest(client_t *con)    /* I - Client connection */
     LogMessage(L_DEBUG2, "ProcessIPPRequest: Adding fd %d to OutputSet...",
                con->http.fd);
 
-    FD_SET(con->http.fd, &OutputSet);
+    FD_SET(con->http.fd, OutputSet);
 
    /*
     * Tell the caller the response header was sent successfully...
@@ -6031,5 +6031,5 @@ validate_user(client_t   *con,            /* I - Client connection */
 
 
 /*
- * End of "$Id: ipp.c,v 1.186 2003/01/31 17:48:23 mike Exp $".
+ * End of "$Id: ipp.c,v 1.187 2003/02/05 21:10:16 mike Exp $".
  */
index e761ed694dcdf10a910e56fd7d18bb09b499addc..25cfe4d3bd2e542abff50465b10f72ae164c423c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: job.c,v 1.185 2003/02/04 05:27:23 mike Exp $"
+ * "$Id: job.c,v 1.186 2003/02/05 21:10:17 mike Exp $"
  *
  *   Job management routines for the Common UNIX Printing System (CUPS).
  *
@@ -1819,7 +1819,7 @@ StartJob(int       id,            /* I - Job ID */
 
   LogMessage(L_DEBUG2, "StartJob: Adding fd %d to InputSet...", current->pipe);
 
-  FD_SET(current->pipe, &InputSet);
+  FD_SET(current->pipe, InputSet);
 }
 
 
@@ -1900,7 +1900,7 @@ StopJob(int id,                   /* I - Job ID */
                     current->pipe);
 
           close(current->pipe);
-         FD_CLR(current->pipe, &InputSet);
+         FD_CLR(current->pipe, InputSet);
          current->pipe = 0;
         }
 
@@ -2106,7 +2106,7 @@ UpdateJob(job_t *job)             /* I - Job to check */
                  job->pipe);
 
       close(job->pipe);
-      FD_CLR(job->pipe, &InputSet);
+      FD_CLR(job->pipe, InputSet);
       job->pipe = 0;
     }
 
@@ -3403,5 +3403,5 @@ start_process(const char *command,        /* I - Full path to command */
 
 
 /*
- * End of "$Id: job.c,v 1.185 2003/02/04 05:27:23 mike Exp $".
+ * End of "$Id: job.c,v 1.186 2003/02/05 21:10:17 mike Exp $".
  */
index 9c4ef4bd396bce459e151f06ccf93ba0f4a52d31..66eac900bedc3922675ef3c1c61cb393ae84b3e8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: listen.c,v 1.16 2003/01/23 16:26:38 mike Exp $"
+ * "$Id: listen.c,v 1.17 2003/02/05 21:10:17 mike Exp $"
  *
  *   Server listening routines for the Common UNIX Printing System (CUPS)
  *   scheduler.
@@ -48,7 +48,7 @@ PauseListening(void)
   listener_t   *lis;           /* Current listening socket */
 
 
-  if (!FD_ISSET(Listeners[0].fd, &InputSet))
+  if (!FD_ISSET(Listeners[0].fd, InputSet))
     return;
 
   if (NumClients == MaxClients)
@@ -61,7 +61,7 @@ PauseListening(void)
     LogMessage(L_DEBUG2, "PauseListening: Removing fd %d from InputSet...",
                lis->fd);
 
-    FD_CLR(lis->fd, &InputSet);
+    FD_CLR(lis->fd, InputSet);
   }
 }
 
@@ -77,7 +77,7 @@ ResumeListening(void)
   listener_t   *lis;           /* Current listening socket */
 
 
-  if (FD_ISSET(Listeners[0].fd, &InputSet))
+  if (FD_ISSET(Listeners[0].fd, InputSet))
     return;
 
   if (NumClients >= (MaxClients - 1))
@@ -90,7 +90,7 @@ ResumeListening(void)
     LogMessage(L_DEBUG2, "ResumeListening: Adding fd %d to InputSet...",
                lis->fd);
 
-    FD_SET(lis->fd, &InputSet);
+    FD_SET(lis->fd, InputSet);
   }
 }
 
@@ -218,5 +218,5 @@ StopListening(void)
 
 
 /*
- * End of "$Id: listen.c,v 1.16 2003/01/23 16:26:38 mike Exp $".
+ * End of "$Id: listen.c,v 1.17 2003/02/05 21:10:17 mike Exp $".
  */
index e40d984660979955144d6da1fee5daccab3ffb66..bfc9a829153cd89ad9330c655fd8f374c4682838 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: main.c,v 1.89 2003/01/31 01:26:32 mike Exp $"
+ * "$Id: main.c,v 1.90 2003/02/05 21:10:17 mike Exp $"
  *
  *   Scheduler main loop for the Common UNIX Printing System (CUPS).
  *
 #  include <malloc.h>
 #endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
 
-#ifndef FD_SETSIZE
-#  define FD_SETSIZE   1024
-#endif /* !FD_SETSIZE */
-
 
 /*
  * Local functions...
@@ -75,8 +71,8 @@ main(int  argc,                       /* I - Number of command-line arguments */
   int                  i;              /* Looping var */
   char                 *opt;           /* Option character */
   int                  fg;             /* Run in the foreground */
-  fd_set               input,          /* Input set for select() */
-                       output;         /* Output set for select() */
+  fd_set               *input,         /* Input set for select() */
+                       *output;        /* Output set for select() */
   client_t             *con;           /* Current client */
   job_t                        *job,           /* Current job */
                        *next;          /* Next job */
@@ -254,14 +250,25 @@ main(int  argc,                   /* I - Number of command-line arguments */
   */
 
   getrlimit(RLIMIT_NOFILE, &limit);
-  if (limit.rlim_max > FD_SETSIZE)     /* Can't exceed size of FD set! */
-    MaxFDs = FD_SETSIZE;
-  else
-    MaxFDs = limit.rlim_max;
-
-  limit.rlim_cur = MaxFDs;
+  limit.rlim_cur = MaxFDs = limit.rlim_max;
   setrlimit(RLIMIT_NOFILE, &limit);
 
+ /*
+  * Allocate memory for the input and output sets...
+  */
+
+  SetSize   = (MaxFDs + 7) / 8;
+  InputSet  = (fd_set *)calloc(1, SetSize);
+  OutputSet = (fd_set *)calloc(1, SetSize);
+  input     = (fd_set *)calloc(1, SetSize);
+  output    = (fd_set *)calloc(1, SetSize);
+
+  if (InputSet == NULL || OutputSet == NULL || input == NULL || output == NULL)
+  {
+    syslog(LOG_LPR, "Unable to allocate memory for select() sets - exiting!");
+    return (1);
+  }
+
  /*
   * Catch hangup and child signals and ignore broken pipes...
   */
@@ -271,6 +278,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
     sigset(SIGHUP, sigterm_handler);
   else
     sigset(SIGHUP, sighup_handler);
+
   sigset(SIGPIPE, SIG_IGN);
   sigset(SIGTERM, sigterm_handler);
 #elif defined(HAVE_SIGACTION)
@@ -411,8 +419,8 @@ main(int  argc,                     /* I - Number of command-line arguments */
     * times.
     */
 
-    input  = InputSet;
-    output = OutputSet;
+    memcpy(input, InputSet, SetSize);
+    memcpy(output, OutputSet, SetSize);
 
     for (i = NumClients, con = Clients; i > 0; i --, con ++)
       if (con->http.used > 0)
@@ -434,7 +442,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
       timeout.tv_usec = 0;
     }
 
-    if ((i = select(MaxFDs, &input, &output, NULL, &timeout)) < 0)
+    if ((i = select(MaxFDs, input, output, NULL, &timeout)) < 0)
     {
       char     s[16384],       /* String buffer */
                *sptr;          /* Pointer into buffer */
@@ -459,7 +467,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
       sptr = s + 10;
 
       for (i = 0; i < MaxFDs; i ++)
-        if (FD_ISSET(i, &InputSet))
+        if (FD_ISSET(i, InputSet))
        {
           snprintf(sptr, sizeof(s) - slen, " %d", i);
          slen += strlen(sptr);
@@ -473,7 +481,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
       sptr = s + 11;
 
       for (i = 0; i < MaxFDs; i ++)
-        if (FD_ISSET(i, &OutputSet))
+        if (FD_ISSET(i, OutputSet))
        {
           snprintf(sptr, sizeof(s) - slen, " %d", i);
          slen += strlen(sptr);
@@ -498,7 +506,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
     }
 
     for (i = NumListeners, lis = Listeners; i > 0; i --, lis ++)
-      if (FD_ISSET(lis->fd, &input))
+      if (FD_ISSET(lis->fd, input))
         AcceptClient(lis);
 
     for (i = NumClients, con = Clients; i > 0; i --, con ++)
@@ -507,7 +515,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
       * Process the input buffer...
       */
 
-      if (FD_ISSET(con->http.fd, &input) || con->http.used)
+      if (FD_ISSET(con->http.fd, input) || con->http.used)
         if (!ReadClient(con))
        {
          con --;
@@ -518,8 +526,8 @@ main(int  argc,                     /* I - Number of command-line arguments */
       * Write data as needed...
       */
 
-      if (FD_ISSET(con->http.fd, &output) &&
-          (!con->pipe_pid || FD_ISSET(con->file, &input)))
+      if (FD_ISSET(con->http.fd, output) &&
+          (!con->pipe_pid || FD_ISSET(con->file, input)))
         if (!WriteClient(con))
        {
          con --;
@@ -550,14 +558,14 @@ main(int  argc,                   /* I - Number of command-line arguments */
     {
       next = job->next;
 
-      if (job->pipe && FD_ISSET(job->pipe, &input))
+      if (job->pipe && FD_ISSET(job->pipe, input))
       {
        /*
         * Clear the input bit to avoid updating the next job
        * using the same status pipe file descriptor...
        */
 
-        FD_CLR(job->pipe, &input);
+        FD_CLR(job->pipe, input);
 
        /*
         * Read any status messages from the filters...
@@ -573,10 +581,10 @@ main(int  argc,                   /* I - Number of command-line arguments */
 
     if (Browsing && BrowseProtocols)
     {
-      if (BrowseSocket >= 0 && FD_ISSET(BrowseSocket, &input))
+      if (BrowseSocket >= 0 && FD_ISSET(BrowseSocket, input))
         UpdateCUPSBrowse();
 
-      if (PollPipe >= 0 && FD_ISSET(PollPipe, &input))
+      if (PollPipe >= 0 && FD_ISSET(PollPipe, input))
         UpdatePolling();
 
 #ifdef HAVE_LIBSLP
@@ -999,5 +1007,5 @@ usage(void)
 
 
 /*
- * End of "$Id: main.c,v 1.89 2003/01/31 01:26:32 mike Exp $".
+ * End of "$Id: main.c,v 1.90 2003/02/05 21:10:17 mike Exp $".
  */
index 7acb74375735703dc52e00a23173bcffb935bf60..ed58ccb727e050b96a050ff72f3dc975618b7db9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: server.c,v 1.6 2003/01/15 04:15:49 mike Exp $"
+ * "$Id: server.c,v 1.7 2003/02/05 21:10:18 mike Exp $"
  *
  *   Server start/stop routines for the Common UNIX Printing System (CUPS).
  *
@@ -148,11 +148,11 @@ StopServer(void)
   * Clear the input and output sets...
   */
 
-  FD_ZERO(&InputSet);
-  FD_ZERO(&OutputSet);
+  memset(InputSet, 0, SetSize);
+  memset(OutputSet, 0, SetSize);
 }
 
 
 /*
- * End of "$Id: server.c,v 1.6 2003/01/15 04:15:49 mike Exp $".
+ * End of "$Id: server.c,v 1.7 2003/02/05 21:10:18 mike Exp $".
  */