]> jfr.im git - irc/rqf/shadowircd.git/blobdiff - src/ircd.c
Much clear maxconnections stuff - ported from ratbox3.
[irc/rqf/shadowircd.git] / src / ircd.c
index 9708dc51e700b7d06c25a2bf859be452710ee573..5e108e0fd864ee202ec77065771de736ed777eb9 100644 (file)
@@ -76,7 +76,7 @@ extern int ServerRunning;
 extern struct LocalUser meLocalUser;
 extern char **myargv;
 
-int maxconnections; /* XXX */
+int maxconnections;
 
 /* /quote set variables */\r
 struct SetOptions GlobalSetOptions;
@@ -153,21 +153,22 @@ ircd_die_cb(const char *str)
 static void
 init_sys(void)
 {
-#if defined(RLIMIT_NOFILE) && defined(HAVE_SYS_RESOURCE_H)
-       struct rlimit limit;
-
-       if(!getrlimit(RLIMIT_NOFILE, &limit))
-       {
-               limit.rlim_cur = limit.rlim_max;        /* make soft limit the max */
-               if(setrlimit(RLIMIT_NOFILE, &limit) == -1)
-               {
-                       fprintf(stderr, "error setting max fd's to %ld\n", (long) limit.rlim_cur);
-                       exit(EXIT_FAILURE);
-               }
-       }
-
-       maxconnections = limit.rlim_cur;
-#endif /* RLIMIT_NOFILE */
+#if defined(RLIMIT_NOFILE) && defined(HAVE_SYS_RESOURCE_H)\r
+       struct rlimit limit;\r
+\r
+       if(!getrlimit(RLIMIT_NOFILE, &limit))\r
+       {\r
+               maxconnections = limit.rlim_cur;\r
+               if(maxconnections <= MAX_BUFFER)\r
+               {\r
+                       fprintf(stderr, "ERROR: Shell FD limits are too low.\n");\r
+                       fprintf(stderr, "ERROR: ircd-ratbox reserves %d FDs, shell limits must be above this\n", MAX_BUFFER);\r
+                       exit(EXIT_FAILURE);\r
+               }\r
+               return;\r
+       }\r
+#endif /* RLIMIT_FD_MAX */\r
+       maxconnections = MAXCONNECTIONS;
 }
 
 static int
@@ -279,7 +280,11 @@ initialize_global_set_options(void)
        memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions));
        /* memset( &ConfigFileEntry, 0, sizeof(ConfigFileEntry)); */
 
-       GlobalSetOptions.maxclients = ServerInfo.max_clients;
+       GlobalSetOptions.maxclients = ServerInfo.default_max_clients;\r
+\r
+       if(GlobalSetOptions.maxclients > (maxconnections - MAX_BUFFER))\r
+               GlobalSetOptions.maxclients = maxconnections - MAX_BUFFER;
+
        GlobalSetOptions.autoconn = 1;
 
        GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME;