Committer  : entrope
CVSROOT    : /cvsroot/undernet-ircu
Module     : ircu2.10
Commit time: 2005-12-29 21:58:09 UTC

Modified files:
     ChangeLog include/ircd.h include/list.h include/s_bsd.h
     ircd/ircd.c ircd/list.c ircd/listener.c ircd/m_trace.c
     ircd/numnicks.c ircd/os_generic.c ircd/s_bsd.c ircd/s_misc.c

Log message:

Add command-line parameters for max connections and clients.

---------------------- diff included ----------------------
Index: ircu2.10/ChangeLog
diff -u ircu2.10/ChangeLog:1.759 ircu2.10/ChangeLog:1.760
--- ircu2.10/ChangeLog:1.759    Wed Dec 28 20:55:13 2005
+++ ircu2.10/ChangeLog  Thu Dec 29 13:57:58 2005
@@ -1,3 +1,42 @@
+2005-12-29  Michael Poole <[EMAIL PROTECTED]>
+
+       * include/ircd.h: Make maxclients and maxconnections variable.
+
+       * include/list.h (init_list): Add maximum connections argument.
+
+       * include/s_bsd.h (HighestFd): Align declaration.
+       (LocalClientArray): Convert into a pointer-to-pointer.
+       (init_connection_limits): Add maximum connections argument.
+
+       * ircd/ircd.c (maxconnections): Define.
+       (maxclients): Define.
+       (parse_command_line): Fix doxygen typo.  Interpret -m <maxconn>
+       and -M <maxclients> arguments.
+       (main): Sanity-check maxconnections and maxclients.
+
+       * ircd/list.c (init_list): Add maximum connections argument.
+
+       * ircd/listener.c (accept_connection): Use maxclients variable.
+
+       * ircd/m_trace.c (do_trace): Dynamically allocate link_s and
+       link_u arrays.
+       (m_trace): Update doxygen comments.
+       (ms_trace): Likewise.
+       (mo_trace): Likewise.
+
+       * ircd/numnicks.c (SetYXXCapacity): Update error message and make
+       it a soft error rather than a fatal one.
+
+       * ircd/os_generic.c (os_socket): Use maxclients variable.
+
+       * ircd/s_bsd.c (LocalClientArray): Update type.
+       (close_connections): Use maxconnections variable.
+       (init_connection_limits): Add maximum connections argument.  Use
+       it to allocate LocalClientArray.
+
+       * ircd/s_misc.c (tstats): Use HighestFd variable instead of
+       MAXCONNECTIONS.
+
 2005-12-28  Michael Poole <[EMAIL PROTECTED]>
 
        * include/sys.h: Delete this file.
Index: ircu2.10/include/ircd.h
diff -u ircu2.10/include/ircd.h:1.15 ircu2.10/include/ircd.h:1.16
--- ircu2.10/include/ircd.h:1.15        Wed Dec 28 20:55:14 2005
+++ ircu2.10/include/ircd.h     Thu Dec 29 13:57:58 2005
@@ -1,6 +1,6 @@
 /** @file ircd.h
  * @brief Global data for the daemon.
- * @version $Id: ircd.h,v 1.15 2005/12/29 04:55:14 entrope Exp $
+ * @version $Id: ircd.h,v 1.16 2005/12/29 21:57:58 entrope Exp $
  */
 #ifndef INCLUDED_ircd_h
 #define INCLUDED_ircd_h
@@ -31,7 +31,6 @@
 #define BadPtr(x) (!(x) || (*(x) == '\0')) /**< Is \a x a bad string? */
 #define IRCD_MAX(a, b)  ((a) > (b) ? (a) : (b)) /**< Find maximum of \a a and 
\a b. */
 #define IRCD_MIN(a, b)  ((a) < (b) ? (a) : (b)) /**< Find minimum of \a a and 
\a b. */
-#define MAXCLIENTS (MAXCONNECTIONS-24) /**< Maximum number of clients to 
accept. */
 
 /* Miscellaneous defines */
 
@@ -56,7 +55,9 @@
 extern char*          configfile;
 extern int            debuglevel;
 extern char*          debugmode;
-extern int           running;
+extern int            running;
+extern int            maxconnections;
+extern int            maxclients;
 
 #endif /* INCLUDED_ircd_h */
 
Index: ircu2.10/include/list.h
diff -u ircu2.10/include/list.h:1.12 ircu2.10/include/list.h:1.13
--- ircu2.10/include/list.h:1.12        Mon May 30 14:07:33 2005
+++ ircu2.10/include/list.h     Thu Dec 29 13:57:58 2005
@@ -1,6 +1,6 @@
 /** @file list.h
  * @brief Singly and doubly linked list manipulation interface.
- * @version $Id: list.h,v 1.12 2005/05/30 21:07:33 entrope Exp $
+ * @version $Id: list.h,v 1.13 2005/12/29 21:57:58 entrope Exp $
  */
 #ifndef INCLUDED_list_h
 #define INCLUDED_list_h
@@ -47,7 +47,7 @@
 
 extern void free_link(struct SLink *lp);
 extern struct SLink *make_link(void);
-extern void init_list(void);
+extern void init_list(int maxconn);
 extern struct Client *make_client(struct Client *from, int status);
 extern void free_connection(struct Connection *con);
 extern void free_client(struct Client *cptr);
Index: ircu2.10/include/s_bsd.h
diff -u ircu2.10/include/s_bsd.h:1.21 ircu2.10/include/s_bsd.h:1.22
--- ircu2.10/include/s_bsd.h:1.21       Mon Jun 27 06:25:51 2005
+++ ircu2.10/include/s_bsd.h    Thu Dec 29 13:57:58 2005
@@ -1,6 +1,6 @@
 /** @file s_bsd.h
  * @brief Wrapper functions to avoid direct use of BSD APIs.
- * @version $Id: s_bsd.h,v 1.21 2005/06/27 13:25:51 entrope Exp $
+ * @version $Id: s_bsd.h,v 1.22 2005/12/29 21:57:58 entrope Exp $
  */
 #ifndef INCLUDED_s_bsd_h
 #define INCLUDED_s_bsd_h
@@ -49,8 +49,8 @@
 extern const char* const TOS_ERROR_MSG;
 extern const char* const REGISTER_ERROR_MSG;
 
-extern int            HighestFd;
-extern struct Client* LocalClientArray[MAXCONNECTIONS];
+extern int                 HighestFd;
+extern struct Client**     LocalClientArray;
 extern struct irc_sockaddr VirtualHost_v4;
 extern struct irc_sockaddr VirtualHost_v6;
 
@@ -65,7 +65,7 @@
 extern int  read_message(time_t delay);
 extern void init_server_identity(void);
 extern void close_connections(int close_stderr);
-extern int  init_connection_limits(void);
+extern int  init_connection_limits(int maxconn);
 extern void update_write(struct Client* cptr);
 
 #endif /* INCLUDED_s_bsd_h */
Index: ircu2.10/ircd/ircd.c
diff -u ircu2.10/ircd/ircd.c:1.93 ircu2.10/ircd/ircd.c:1.94
--- ircu2.10/ircd/ircd.c:1.93   Wed Dec 28 20:55:16 2005
+++ ircu2.10/ircd/ircd.c        Thu Dec 29 13:57:59 2005
@@ -19,7 +19,7 @@
  */
 /** @file
  * @brief Entry point and other initialization functions for the daemon.
- * @version $Id: ircd.c,v 1.93 2005/12/29 04:55:16 entrope Exp $
+ * @version $Id: ircd.c,v 1.94 2005/12/29 21:57:59 entrope Exp $
  */
 #include "config.h"
 
@@ -111,6 +111,8 @@
 char          *configfile        = CPATH; /**< Server configuration file */
 int            debuglevel        = -1;    /**< Server debug level  */
 char          *debugmode         = "";    /**< Server debug level */
+int            maxconnections    = MAXCONNECTIONS; /**< Maximum number of open 
files */
+int            maxclients        = -1;    /**< Maximum number of clients */
 static char   *dpath             = DPATH; /**< Working directory for daemon */
 static char   *dbg_client;                /**< Client specifier for chkconf */
 
@@ -454,10 +456,10 @@
  * As a side effect, makes sure the process's effective user id is the
  * same as the real user id.
  * @param[in] argc Number of arguments on command line.
- * @param[in,out] argv Command-lne arguments.
+ * @param[in,out] argv Command-line arguments.
  */
 static void parse_command_line(int argc, char** argv) {
-  const char *options = "d:f:h:nktvx:c:";
+  const char *options = "d:f:h:nktvx:c:m:M:";
   int opt;
 
   if (thisServer.euid != thisServer.uid)
@@ -475,6 +477,8 @@
     case 'd':  dpath      = optarg;                    break;
     case 'f':  configfile = optarg;                    break;
     case 'h':  ircd_strncpy(cli_name(&me), optarg, HOSTLEN); break;
+    case 'm':  maxconnections = atoi(optarg);          break;
+    case 'M':  maxclients = atoi(optarg);              break;
     case 'v':
       printf("ircd %s\n", version);
       printf("Event engines: ");
@@ -492,7 +496,7 @@
 #else
       printf("select()");
 #endif
-      printf("\nCompiled for a maximum of %d connections.\n", MAXCONNECTIONS);
+      printf("\nDefaulting to %d connections.\n", MAXCONNECTIONS);
 
 
       exit(0);
@@ -507,11 +511,13 @@
       break;
 
     default:
-      printf("Usage: ircd [-f config] [-h servername] [-x loglevel] [-ntv] [-k 
[-c clispec]]\n"
+      printf("Usage: ircd [-f config] [-h servername] [-x loglevel] [-ntv] [-m 
maxconn] [-M maxclients] [-k [-c clispec]]\n"
              "\n -f config\t specify explicit configuration file"
              "\n -x loglevel\t set debug logging verbosity"
              "\n -n or -t\t don't detach"
              "\n -v\t\t display version"
+             "\n -m\t\t set maximum number of connections"
+             "\n -M\t\t set maximum number of clients"
              "\n -k\t\t exit after checking config"
              "\n -c clispec\t search for client/kill blocks matching client"
              "\n\t\t clispec is comma-separated list of [EMAIL PROTECTED],"
@@ -636,6 +642,20 @@
 
   parse_command_line(argc, argv);
 
+  if (maxconnections < 32) {
+    fprintf(stderr,
+            "Fewer than 32 connections are not supported.  Reconfigure or use 
-m 32.\n");
+    return 2;
+  } else if (maxclients > maxconnections) {
+    fprintf(stderr,
+            "Maxclients (%d) must not exceed maxconnections (%d).  Reconfigure 
or use -m %d.\n", maxclients, maxconnections, maxclients + 24);
+    return 2;
+  } else if (maxclients > maxconnections - 24) {
+    fprintf(stderr,
+            "Maxclients (%d) is within 24 of maxconnections (%d).  This may 
cause problems.\n", maxclients, maxconnections);
+  } else if (maxclients < 0)
+    maxclients = maxconnections - 24;
+
   if (chdir(dpath)) {
     fprintf(stderr, "Fail: Cannot chdir(%s): %s, check DPATH\n", dpath, 
strerror(errno));
     return 2;
@@ -649,7 +669,7 @@
       !check_file_access(configfile, 'C', R_OK))
     return 4;
 
-  if (!init_connection_limits())
+  if (!init_connection_limits(maxconnections))
     return 9;
 
   close_connections(!(thisServer.bootopt & (BOOT_DEBUG | BOOT_TTY | 
BOOT_CHKCONF)));
@@ -676,7 +696,7 @@
   }
 #endif
 
-  event_init(MAXCONNECTIONS);
+  event_init(maxconnections);
 
   setup_signals();
   init_isupport();
@@ -685,7 +705,7 @@
   set_nomem_handler(outofmemory);
 
   initload();
-  init_list();
+  init_list(maxconnections);
   init_hash();
   init_class();
   initwhowas();
@@ -714,7 +734,7 @@
   debug_init(thisServer.bootopt & BOOT_TTY);
   if (check_pid()) {
     Debug((DEBUG_FATAL, "Failed to acquire PID file lock after fork"));
-    exit(2);
+    return 2;
   }
 
   init_server_identity();
@@ -741,7 +761,7 @@
   cli_serv(&me)->down      = NULL;
   cli_handler(&me)         = SERVER_HANDLER;
 
-  SetYXXCapacity(&me, MAXCLIENTS);
+  SetYXXCapacity(&me, maxclients);
 
   cli_lasttime(&me) = cli_since(&me) = cli_firsttime(&me) = CurrentTime;
 
Index: ircu2.10/ircd/list.c
diff -u ircu2.10/ircd/list.c:1.34 ircu2.10/ircd/list.c:1.35
--- ircu2.10/ircd/list.c:1.34   Mon Jun 27 06:25:51 2005
+++ ircu2.10/ircd/list.c        Thu Dec 29 13:57:59 2005
@@ -19,7 +19,7 @@
  */
 /** @file
  * @brief Singly and doubly linked list manipulation implementation.
- * @version $Id: list.c,v 1.34 2005/06/27 13:25:51 entrope Exp $
+ * @version $Id: list.c,v 1.35 2005/12/29 21:57:59 entrope Exp $
  */
 #include "config.h"
 
@@ -67,17 +67,17 @@
 static struct SLink* slinkFreeList;
 
 /** Initialize the list manipulation support system.
- * Pre-allocate MAXCONNECTIONS Client and Connection structures.
+ * @arg[in] maxconn Number of Client and Connection structures to preallocate.
  */
-void init_list(void)
+void init_list(int maxconn)
 {
   struct Client* cptr;
   struct Connection* con;
   int i;
   /*
-   * pre-allocate MAXCONNECTIONS clients and connections
+   * pre-allocate \a maxconn clients and connections
    */
-  for (i = 0; i < MAXCONNECTIONS; ++i) {
+  for (i = 0; i < maxconn; ++i) {
     cptr = (struct Client*) MyMalloc(sizeof(struct Client));
     cli_next(cptr) = clientFreeList;
     clientFreeList = cptr;
Index: ircu2.10/ircd/listener.c
diff -u ircu2.10/ircd/listener.c:1.29 ircu2.10/ircd/listener.c:1.30
--- ircu2.10/ircd/listener.c:1.29       Wed Dec 28 20:55:16 2005
+++ ircu2.10/ircd/listener.c    Thu Dec 29 13:57:59 2005
@@ -18,7 +18,7 @@
  */
 /** @file
  * @brief Implementation for handling listening sockets.
- * @version $Id: listener.c,v 1.29 2005/12/29 04:55:16 entrope Exp $
+ * @version $Id: listener.c,v 1.30 2005/12/29 21:57:59 entrope Exp $
  */
 #include "config.h"
 
@@ -416,7 +416,7 @@
        * Enable the server to clear out other connections before
        * continuing to accept() new connections.
        */
-      if (fd > MAXCLIENTS - 1)
+      if (fd >= maxclients)
       {
         ++ServerStats->is_ref;
         send(fd, "ERROR :All connections in use\r\n", 32, 0);
Index: ircu2.10/ircd/m_trace.c
diff -u ircu2.10/ircd/m_trace.c:1.13 ircu2.10/ircd/m_trace.c:1.14
--- ircu2.10/ircd/m_trace.c:1.13        Thu Aug 25 20:23:23 2005
+++ ircu2.10/ircd/m_trace.c     Thu Dec 29 13:57:59 2005
@@ -20,71 +20,16 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: m_trace.c,v 1.13 2005/08/26 03:23:23 entrope Exp $
+ * $Id: m_trace.c,v 1.14 2005/12/29 21:57:59 entrope Exp $
  */
 
-/*
- * m_functions execute protocol messages on this server:
- *
- *    cptr    is always NON-NULL, pointing to a *LOCAL* client
- *            structure (with an open socket connected!). This
- *            identifies the physical socket where the message
- *            originated (or which caused the m_function to be
- *            executed--some m_functions may call others...).
- *
- *    sptr    is the source of the message, defined by the
- *            prefix part of the message if present. If not
- *            or prefix not found, then sptr==cptr.
- *
- *            (!IsServer(cptr)) => (cptr == sptr), because
- *            prefixes are taken *only* from servers...
- *
- *            (IsServer(cptr))
- *                    (sptr == cptr) => the message didn't
- *                    have the prefix.
- *
- *                    (sptr != cptr && IsServer(sptr) means
- *                    the prefix specified servername. (?)
- *
- *                    (sptr != cptr && !IsServer(sptr) means
- *                    that message originated from a remote
- *                    user (not local).
- *
- *            combining
- *
- *            (!IsServer(sptr)) means that, sptr can safely
- *            taken as defining the target structure of the
- *            message in this server.
- *
- *    *Always* true (if 'parse' and others are working correct):
- *
- *    1)      sptr->from == cptr  (note: cptr->from == cptr)
- *
- *    2)      MyConnect(sptr) <=> sptr == cptr (e.g. sptr
- *            *cannot* be a local connection, unless it's
- *            actually cptr!). [MyConnect(x) should probably
- *            be defined as (x == x->from) --msa ]
- *
- *    parc    number of variable parameter strings (if zero,
- *            parv is allowed to be NULL)
- *
- *    parv    a NULL terminated list of parameter pointers,
- *
- *                    parv[0], sender (prefix string), if not present
- *                            this points to an empty string.
- *                    parv[1]...parv[parc-1]
- *                            pointers to additional parameters
- *                    parv[parc] == NULL, *always*
- *
- *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
- *                    non-NULL pointers.
- */
 #include "config.h"
 
 #include "class.h"
 #include "client.h"
 #include "hash.h"
 #include "ircd.h"
+#include "ircd_alloc.h"
 #include "ircd_features.h"
 #include "ircd_log.h"
 #include "ircd_reply.h"
@@ -110,8 +55,8 @@
   const struct ConnectionClass* cl;
   char* tname;
   int doall;
-  int link_s[MAXCONNECTIONS];
-  int link_u[MAXCONNECTIONS];
+  int *link_s;
+  int *link_u;
   int cnt = 0;
   int wilds;
   int dow;
@@ -178,8 +123,8 @@
     return;
   }
 
-  for (i = 0; i < MAXCONNECTIONS; i++)
-    link_s[i] = 0, link_u[i] = 0;
+  link_s = MyCalloc(2 * maxconnections, sizeof(link_s[0]));
+  link_u = link_s + maxconnections;
 
   if (doall) {
     for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr)) {
@@ -298,14 +243,20 @@
     }
   }
   send_reply(sptr, RPL_TRACEEND);
+  MyFree(link_s);
 }
 
-/*
- * m_trace - generic message handler
+/** Handle a TRACE message from a local luser.
  *
- * parv[0] = sender prefix
- * parv[1] = nick or servername
- * parv[2] = 'target' servername
+ * \a parv has the following elements:
+ * \li \a parv[1] is the nick or servername to trace
+ * \li \a parv[2] is the optional 'target' server to trace from
+ *
+ * See @ref m_functions for discussion of the arguments.
+ * @param[in] cptr Client that sent us the message.
+ * @param[in] sptr Original source of message.
+ * @param[in] parc Number of arguments.
+ * @param[in] parv Argument vector.
  */
 int m_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 {
@@ -315,12 +266,17 @@
   return 0;
 }
 
-/*
- * ms_trace - server message handler
+/** Handle a TRACE message from a server.
  *
- * parv[0] = sender prefix
- * parv[1] = nick or servername
- * parv[2] = 'target' servername
+ * \a parv has the following elements:
+ * \li \a parv[1] is the nick or servername to trace
+ * \li \a parv[2] is the mandatory 'target' server to trace from
+ *
+ * See @ref m_functions for discussion of the arguments.
+ * @param[in] cptr Client that sent us the message.
+ * @param[in] sptr Original source of message.
+ * @param[in] parc Number of arguments.
+ * @param[in] parv Argument vector.
  */
 int ms_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 {
@@ -328,12 +284,17 @@
   return 0;
 }
 
-/*
- * mo_trace - oper message handler
+/** Handle a TRACE message from a local oper.
  *
- * parv[0] = sender prefix
- * parv[1] = nick or servername
- * parv[2] = 'target' servername
+ * \a parv has the following elements:
+ * \li \a parv[1] is the nick or servername to trace
+ * \li \a parv[2] is the optional 'target' server to trace from
+ *
+ * See @ref m_functions for discussion of the arguments.
+ * @param[in] cptr Client that sent us the message.
+ * @param[in] sptr Original source of message.
+ * @param[in] parc Number of arguments.
+ * @param[in] parv Argument vector.
  */
 int mo_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 {
Index: ircu2.10/ircd/numnicks.c
diff -u ircu2.10/ircd/numnicks.c:1.30 ircu2.10/ircd/numnicks.c:1.31
--- ircu2.10/ircd/numnicks.c:1.30       Sat May  7 17:56:05 2005
+++ ircu2.10/ircd/numnicks.c    Thu Dec 29 13:57:59 2005
@@ -18,7 +18,7 @@
  */
 /** @file
  * @brief Implementation of numeric nickname operations.
- * @version $Id: numnicks.c,v 1.30 2005/05/08 00:56:05 entrope Exp $
+ * @version $Id: numnicks.c,v 1.31 2005/12/29 21:57:59 entrope Exp $
  */
 #include "config.h"
 
@@ -279,10 +279,10 @@
    * Sanity checks
    */
   if (max_clients > NN_MAX_CLIENT) {
-    fprintf(stderr, "MAXCLIENTS (or MAXCONNECTIONS) is (at least) %d "
-            "too large ! Please decrease this value.\n",
-             max_clients - NN_MAX_CLIENT);
-    exit(-1);
+    fprintf(stderr, "maxclients (or maxconnections) is %d too large,"
+            " please decrease this value.\n",
+            capacity - NN_MAX_CLIENT);
+    max_clients = NN_MAX_CLIENT;
   }
   --max_clients;
   inttobase64(cli_serv(c)->nn_capacity, max_clients, 3);
Index: ircu2.10/ircd/os_generic.c
diff -u ircu2.10/ircd/os_generic.c:1.24 ircu2.10/ircd/os_generic.c:1.25
--- ircu2.10/ircd/os_generic.c:1.24     Wed Dec 28 20:55:16 2005
+++ ircu2.10/ircd/os_generic.c  Thu Dec 29 13:57:59 2005
@@ -18,7 +18,7 @@
  */
 /** @file
  * @brief Implementation of OS-dependent operations.
- * @version $Id: os_generic.c,v 1.24 2005/12/29 04:55:16 entrope Exp $
+ * @version $Id: os_generic.c,v 1.25 2005/12/29 21:57:59 entrope Exp $
  */
 #include "config.h"
 
@@ -617,7 +617,7 @@
     report_error(SOCKET_ERROR_MSG, port_name, errno);
     return -1;
   }
-  if (fd > MAXCLIENTS - 1) {
+  if (fd >= maxclients) {
     report_error(CONNLIMIT_ERROR_MSG, port_name, 0);
     close(fd);
     return -1;
Index: ircu2.10/ircd/s_bsd.c
diff -u ircu2.10/ircd/s_bsd.c:1.81 ircu2.10/ircd/s_bsd.c:1.82
--- ircu2.10/ircd/s_bsd.c:1.81  Wed Dec 28 20:55:16 2005
+++ ircu2.10/ircd/s_bsd.c       Thu Dec 29 13:57:59 2005
@@ -19,7 +19,7 @@
  */
 /** @file
  * @brief Functions that now (or in the past) relied on BSD APIs.
- * @version $Id: s_bsd.c,v 1.81 2005/12/29 04:55:16 entrope Exp $
+ * @version $Id: s_bsd.c,v 1.82 2005/12/29 21:57:59 entrope Exp $
  */
 #include "config.h"
 
@@ -71,7 +71,7 @@
 #include <unistd.h>
 
 /** Array of my own clients, indexed by file descriptor. */
-struct Client*            LocalClientArray[MAXCONNECTIONS];
+struct Client**           LocalClientArray;
 /** Maximum file descriptor in current use. */
 int                       HighestFd = -1;
 /** Default local address for outbound IPv4 connections. */
@@ -175,24 +175,32 @@
     close(1);
     close(2);
   }
-  for (i = 3; i < MAXCONNECTIONS; ++i)
+  for (i = 3; i < maxconnections; ++i)
     close(i);
 }
 
-/** Initialize process fd limit to MAXCONNECTIONS.
- */
-int init_connection_limits(void)
-{
-  int limit = os_set_fdlimit(MAXCONNECTIONS);
-  if (0 == limit)
+/** Initialize process fd limit.
+ * @param[in] maxconn Maximum number of connections to support.
+ * @return Non-zero on success, zero on error.
+ */
+int init_connection_limits(int maxconn)
+{
+  int limit = os_set_fdlimit(maxconn);
+  if (0 == limit) {
+    LocalClientArray = MyCalloc(maxconn, sizeof(LocalClientArray[0]));
+    if (!LocalClientArray) {
+      fprintf(stderr, "unable to allocate client array for %d clients\n", 
maxconn);
+      return 0;
+    }
     return 1;
+  }
   if (limit < 0) {
-    fprintf(stderr, "error setting max fd's to %d\n", limit);
+    fprintf(stderr, "error setting max fd's to %d\n", maxconn);
   }
   else if (limit > 0) {
-    fprintf(stderr, "ircd fd table too big\nHard Limit: %d IRC max: %d\n",
-            limit, MAXCONNECTIONS);
-    fprintf(stderr, "set MAXCONNECTIONS to a smaller value");
+    fprintf(stderr, "ircd fd table too big\nHard Limit: %d IRC max: %d\n"
+            "set MAXCONNECTIONS or -m to a smaller value\n",
+            limit, maxconn);
   }
   return 0;
 }
Index: ircu2.10/ircd/s_misc.c
diff -u ircu2.10/ircd/s_misc.c:1.51 ircu2.10/ircd/s_misc.c:1.52
--- ircu2.10/ircd/s_misc.c:1.51 Wed Dec 28 20:55:16 2005
+++ ircu2.10/ircd/s_misc.c      Thu Dec 29 13:57:59 2005
@@ -22,7 +22,7 @@
  */
 /** @file
  * @brief Miscellaneous support functions.
- * @version $Id: s_misc.c,v 1.51 2005/12/29 04:55:16 entrope Exp $
+ * @version $Id: s_misc.c,v 1.52 2005/12/29 21:57:59 entrope Exp $
  */
 #include "config.h"
 
@@ -554,7 +554,7 @@
 
   sp = &tmp;
   memcpy(sp, ServerStats, sizeof(struct ServerStatistics));
-  for (i = 0; i < MAXCONNECTIONS; i++)
+  for (i = 0; i < HighestFd; i++)
   {
     if (!(acptr = LocalClientArray[i]))
       continue;
----------------------- End of diff -----------------------
_______________________________________________
Patches mailing list
[email protected]
http://undernet.sbg.org/mailman/listinfo/patches

Reply via email to