From 101db4c4433a7b30fe5986583abc898f554ebd7b Mon Sep 17 00:00:00 2001 From: Valery Yatsko Date: Sat, 5 Apr 2008 23:56:15 +0400 Subject: [PATCH] Much clear maxconnections stuff - ported from ratbox3. --- doc/example.conf | 10 +++++----- doc/reference.conf | 10 +++++----- include/defaults.h | 3 +++ include/s_conf.h | 2 +- modules/m_info.c | 10 +++++----- modules/m_set.c | 16 ++++++++-------- src/ircd.c | 39 ++++++++++++++++++++++----------------- src/newconf.c | 2 +- src/restart.c | 2 -- src/s_conf.c | 2 +- 10 files changed, 51 insertions(+), 45 deletions(-) diff --git a/doc/example.conf b/doc/example.conf index fbac4a08..3346ce7b 100755 --- a/doc/example.conf +++ b/doc/example.conf @@ -43,12 +43,12 @@ serverinfo { /* for IPv6 */ #vhost6 = "3ffe:80e8:546::2"; - /* max_clients: This should be set to the maximum amount of clients - * that the server should support. Note that you should leave some - * file descriptors free for log files, server connections, ident - * lookups (if enabled), exceed_limit clients, etc. + /* default max clients: the default maximum number of clients + * allowed to connect. This can be changed once ircd has started by + * issuing: + * /quote set maxclients */ - max_clients = 1024; + default_max_clients = 1024; }; admin { diff --git a/doc/reference.conf b/doc/reference.conf index 3238f39a..e1a6e6fd 100755 --- a/doc/reference.conf +++ b/doc/reference.conf @@ -116,12 +116,12 @@ serverinfo { */ #vhost6 = "3ffe:80e8:546::2"; - /* max_clients: this should be set to the maximum amount of clients - * that the server should support. Note that you should leave some - * file descriptors free for log files, server connections, ident - * lookups (if enabled), exceed_limit clients, etc. + /* default max clients: the default maximum number of clients + * allowed to connect. This can be changed once ircd has started by + * issuing: + * /quote set maxclients */ - max_clients = 1024; + default_max_clients = 1024; }; /* admin {}: contains admin information about the server. (OLD A:) */ diff --git a/include/defaults.h b/include/defaults.h index 99d64471..5edd8b83 100644 --- a/include/defaults.h +++ b/include/defaults.h @@ -34,6 +34,9 @@ /* * First, set other fd limits based on values from user */ + + +#define MAXCONNECTIONS 65535 /* default max connections if getrlimit doesn't work */ /* class {} default values */ #define DEFAULT_SENDQ 20000000 /* default max SendQ */ #define PORTNUM 6667 /* default outgoing portnum */ diff --git a/include/s_conf.h b/include/s_conf.h index 2a7661d8..79a8766f 100644 --- a/include/s_conf.h +++ b/include/s_conf.h @@ -279,7 +279,7 @@ struct server_info int specific_ipv6_vhost; #endif - int max_clients; + int default_max_clients; }; struct admin_info diff --git a/modules/m_info.c b/modules/m_info.c index 5bbad557..aed3469d 100644 --- a/modules/m_info.c +++ b/modules/m_info.c @@ -91,11 +91,11 @@ static struct InfoStruct info_table[] = { &opers_see_all_users, "Farconnect notices available or operspy accountability limited" }, - { - "max_clients", - OUTPUT_DECIMAL, - &ServerInfo.max_clients, - "Maximum clients allowed (configured)", + { + "max_connections", + OUTPUT_DECIMAL, + &maxconnections, + "Max number connections" }, { "anti_nick_flood", diff --git a/modules/m_set.c b/modules/m_set.c index 0224a369..3f336c1e 100644 --- a/modules/m_set.c +++ b/modules/m_set.c @@ -215,18 +215,18 @@ quote_max(struct Client *source_p, int newval) { if(newval > 0) { - if(newval > ServerInfo.max_clients) - { - sendto_one_notice(source_p, - ":You cannot set MAXCLIENTS to > max_clients (%d)", - ServerInfo.max_clients); - return; + if(newval > maxconnections - MAX_BUFFER) + { + sendto_one_notice(source_p, + ":You cannot set MAXCLIENTS to > %d", + maxconnections - MAX_BUFFER); + return; } if(newval < 32) { - sendto_one_notice(source_p, ":You cannot set MAXCLIENTS to < 32 (%d)", - GlobalSetOptions.maxclients); + sendto_one_notice(source_p, ":You cannot set MAXCLIENTS to < 32 (%d:%d)", + GlobalSetOptions.maxclients, rb_getmaxconnect()); return; } diff --git a/src/ircd.c b/src/ircd.c index 9708dc51..5e108e0f 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -76,7 +76,7 @@ extern int ServerRunning; extern struct LocalUser meLocalUser; extern char **myargv; -int maxconnections; /* XXX */ +int maxconnections; /* /quote set variables */ 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) + struct rlimit limit; + + if(!getrlimit(RLIMIT_NOFILE, &limit)) + { + maxconnections = limit.rlim_cur; + if(maxconnections <= MAX_BUFFER) + { + fprintf(stderr, "ERROR: Shell FD limits are too low.\n"); + fprintf(stderr, "ERROR: ircd-ratbox reserves %d FDs, shell limits must be above this\n", MAX_BUFFER); + exit(EXIT_FAILURE); + } + return; + } +#endif /* RLIMIT_FD_MAX */ + 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; + + if(GlobalSetOptions.maxclients > (maxconnections - MAX_BUFFER)) + GlobalSetOptions.maxclients = maxconnections - MAX_BUFFER; + GlobalSetOptions.autoconn = 1; GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME; diff --git a/src/newconf.c b/src/newconf.c index ce3fe844..e2032dad 100644 --- a/src/newconf.c +++ b/src/newconf.c @@ -1893,7 +1893,7 @@ static struct ConfEntry conf_serverinfo_table[] = { "vhost", CF_QSTRING, conf_set_serverinfo_vhost, 0, NULL }, { "vhost6", CF_QSTRING, conf_set_serverinfo_vhost6, 0, NULL }, - { "max_clients", CF_INT, NULL, 0, &ServerInfo.max_clients }, + { "default_max_clients",CF_INT, NULL, 0, &ServerInfo.default_max_clients }, { "\0", 0, NULL, 0, NULL } }; diff --git a/src/restart.c b/src/restart.c index 7dc5cf0e..ada978cf 100644 --- a/src/restart.c +++ b/src/restart.c @@ -36,8 +36,6 @@ /* external var */ extern char **myargv; -extern int maxconnections; /* XXX */ - void restart(const char *mesg) { diff --git a/src/s_conf.c b/src/s_conf.c index c0033d19..db2eba74 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -838,7 +838,7 @@ set_default_conf(void) ConfigFileEntry.reject_duration = 120; ConfigFileEntry.max_unknown_ip = 2; - ServerInfo.max_clients = maxconnections - MAX_BUFFER; + ServerInfo.default_max_clients = MAXCONNECTIONS; } #undef YES