From 6fcb8629ae638cceeead036a7240821c9886fe0f Mon Sep 17 00:00:00 2001 From: nenolod Date: Tue, 3 Apr 2007 02:21:31 -0700 Subject: [PATCH] [svn] - remove ALL braindead 2.8 I/O artifacts: MASTER_MAX, HARD_FDLIMIT, HARD_FDLIMIT_, MAXCONNECTIONS, MAX_CLIENTS, etc. they are ALL gone. all of this stuff is now determined at runtime via getrlimit(2). - due to this, devpoll is broken. i'm not motivated to fix it at the moment. --- ChangeLog | 9 ++++++++ include/config.h | 7 +----- include/config.h.dist | 7 +----- include/defaults.h | 8 +------ include/m_info.h | 5 +---- include/serno.h | 2 +- libcharybdis/commio.c | 30 ++++++++++++++++++------- libcharybdis/commio.h | 4 +++- libcharybdis/devpoll.c | 5 ++--- libcharybdis/poll.c | 9 ++++---- libcharybdis/select.c | 5 +---- src/ircd.c | 11 +-------- src/listener.c | 51 ++++++++++++++++++++---------------------- src/restart.c | 5 +++-- src/s_auth.c | 8 +++++-- src/s_conf.c | 4 ++-- src/s_serv.c | 6 +++-- 17 files changed, 87 insertions(+), 89 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7a2016125..b9f0d18d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +jilles 2007/04/02 22:03:08 UTC (20070402-3350) + Log: + Repair operspy who !#channel, broken by me in r3283. + + + Changes: Modified: + +2 -2 trunk/modules/m_who.c (File Modified) + + jilles 2007/04/01 22:20:00 UTC (20070401-3344) Log: Update bug report and IRC channel information. diff --git a/include/config.h b/include/config.h index 78c48f016..860af7b88 100644 --- a/include/config.h +++ b/include/config.h @@ -21,7 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: config.h 1701 2006-06-27 16:25:52Z jilles $ + * $Id: config.h 3354 2007-04-03 09:21:31Z nenolod $ */ #ifndef INCLUDED_config_h @@ -146,11 +146,6 @@ */ #define MAX_BUFFER 60 -/* HARD_FDLIMIT_ - * The maximum amount of FDs to use. MAX_CLIENTS is set in ./configure. - */ -#define HARD_FDLIMIT_ MAX_CLIENTS + MAX_BUFFER + 20 - #define CONFIG_RATBOX_LEVEL_2 #include "defaults.h" diff --git a/include/config.h.dist b/include/config.h.dist index b80d8ee24..93e017706 100644 --- a/include/config.h.dist +++ b/include/config.h.dist @@ -21,7 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: config.h.dist 3275 2007-03-18 16:29:31Z jilles $ + * $Id: config.h.dist 3354 2007-04-03 09:21:31Z nenolod $ */ #ifndef INCLUDED_config_h @@ -159,11 +159,6 @@ */ #define MAX_BUFFER 60 -/* HARD_FDLIMIT_ - * The maximum amount of FDs to use. MAX_CLIENTS is set in ./configure. - */ -#define HARD_FDLIMIT_ MAX_CLIENTS + MAX_BUFFER + 20 - #define CONFIG_RATBOX_LEVEL_2 #include "defaults.h" diff --git a/include/defaults.h b/include/defaults.h index a0889fec7..99d644719 100644 --- a/include/defaults.h +++ b/include/defaults.h @@ -21,7 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: defaults.h 6 2005-09-10 01:02:21Z nenolod $ + * $Id: defaults.h 3354 2007-04-03 09:21:31Z nenolod $ */ #ifndef INCLUDED_defaults_h @@ -34,12 +34,6 @@ /* * First, set other fd limits based on values from user */ -#ifndef HARD_FDLIMIT_ -error HARD_FDLIMIT_ undefined -#endif -#define HARD_FDLIMIT (HARD_FDLIMIT_ - 10) -#define MAXCONNECTIONS HARD_FDLIMIT -#define MASTER_MAX (HARD_FDLIMIT - MAX_BUFFER) /* class {} default values */ #define DEFAULT_SENDQ 20000000 /* default max SendQ */ #define PORTNUM 6667 /* default outgoing portnum */ diff --git a/include/m_info.h b/include/m_info.h index 141133f92..e60fb3ac1 100644 --- a/include/m_info.h +++ b/include/m_info.h @@ -21,7 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: m_info.h 70 2005-09-10 07:03:09Z nenolod $ + * $Id: m_info.h 3354 2007-04-03 09:21:31Z nenolod $ */ #ifndef INCLUDED_m_info_h @@ -64,9 +64,6 @@ Info MyInformation[] = { {"RESVPATH", "NONE", 0, "Path to resv file"}, #endif - {"HARD_FDLIMIT_", "", HARD_FDLIMIT_, - "Maximum Number of File Descriptors Available"}, - #ifdef HPATH {"HPATH", HPATH, 0, "Path to Operator Help Files"}, #else diff --git a/include/serno.h b/include/serno.h index 19f6cbd51..10f546040 100644 --- a/include/serno.h +++ b/include/serno.h @@ -1 +1 @@ -#define SERNO "20070401-3344" +#define SERNO "20070402-3350" diff --git a/libcharybdis/commio.c b/libcharybdis/commio.c index 2985fc2f0..14c9efaf1 100644 --- a/libcharybdis/commio.c +++ b/libcharybdis/commio.c @@ -21,7 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: commio.c 3247 2007-03-05 18:42:24Z nenolod $ + * $Id: commio.c 3354 2007-04-03 09:21:31Z nenolod $ */ #include "libcharybdis.h" @@ -56,6 +56,7 @@ static void comm_connect_callback(int fd, int status); static PF comm_connect_timeout; static void comm_connect_dns_callback(void *vptr, struct DNSReply *reply); static PF comm_connect_tryconnect; +static int comm_max_connections = 0; inline fde_t * comm_locate_fd(int fd) @@ -140,10 +141,11 @@ comm_close_all(void) int fd; #endif - /* XXX someone tell me why we care about 4 fd's ? */ - /* XXX btw, fd 3 is used for profiler ! */ - - for (i = 4; i < MAXCONNECTIONS; ++i) + /* + * we start at 4 to avoid giving fds where malloc messages + * could be written --nenolod + */ + for (i = 4; i < comm_max_connections; ++i) { fde_t *F = comm_locate_fd(i); @@ -600,7 +602,7 @@ comm_socket(int family, int sock_type, int proto, const char *note) { int fd; /* First, make sure we aren't going to run out of file descriptors */ - if(number_fd >= MASTER_MAX) + if(number_fd >= comm_max_connections) { errno = ENFILE; return -1; @@ -658,7 +660,7 @@ int comm_accept(int fd, struct sockaddr *pn, socklen_t *addrlen) { int newfd; - if(number_fd >= MASTER_MAX) + if(number_fd >= comm_max_connections) { errno = ENFILE; return -1; @@ -722,7 +724,7 @@ fdlist_update_biggest(int fd, int opening) { if(fd < highest_fd) return; - s_assert(fd < MAXCONNECTIONS); + s_assert(fd < comm_max_connections); if(fd > highest_fd) { @@ -749,10 +751,16 @@ void fdlist_init(void) { static int initialized = 0; + struct rlimit limit; if(!initialized) { memset(&fd_table, '\0', sizeof(dlink_list) * FD_HASH_SIZE); + + /* set up comm_max_connections. */ + if(!getrlimit(RLIMIT_NOFILE, &limit)) + comm_max_connections = limit.rlim_cur; + initialized = 1; } } @@ -870,4 +878,10 @@ comm_note(int fd, const char *format, ...) F->desc[0] = '\0'; } +extern int +comm_get_maxconnections(void) +{ + fdlist_init(); + return comm_max_connections; +} diff --git a/libcharybdis/commio.h b/libcharybdis/commio.h index c8d44d4cb..f7240609d 100644 --- a/libcharybdis/commio.h +++ b/libcharybdis/commio.h @@ -21,7 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: commio.h 3229 2007-03-05 17:23:07Z nenolod $ + * $Id: commio.h 3354 2007-04-03 09:21:31Z nenolod $ */ #ifndef INCLUDED_commio_h @@ -188,6 +188,8 @@ extern void mangle_mapped_sockaddr(struct sockaddr *in); #define mangle_mapped_sockaddr(x) #endif +extern int comm_get_maxconnections(void); + extern fde_t *comm_locate_fd(int fd); #endif /* INCLUDED_commio_h */ diff --git a/libcharybdis/devpoll.c b/libcharybdis/devpoll.c index e8934bad1..bd2eeae66 100644 --- a/libcharybdis/devpoll.c +++ b/libcharybdis/devpoll.c @@ -22,7 +22,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: devpoll.c 3229 2007-03-05 17:23:07Z nenolod $ + * $Id: devpoll.c 3354 2007-04-03 09:21:31Z nenolod $ */ #include "config.h" @@ -32,8 +32,7 @@ #include "libcharybdis.h" -#define POLL_LENGTH HARD_FDLIMIT - +#define POLL_LENGTH 1024 static void devpoll_update_events(int, short, PF *); static int dpfd; diff --git a/libcharybdis/poll.c b/libcharybdis/poll.c index 73cb31e06..8023b1124 100644 --- a/libcharybdis/poll.c +++ b/libcharybdis/poll.c @@ -22,7 +22,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: poll.c 3245 2007-03-05 18:41:14Z nenolod $ + * $Id: poll.c 3354 2007-04-03 09:21:31Z nenolod $ */ #include "config.h" @@ -63,14 +63,15 @@ void init_netio(void) { int fd; + int maxconn = comm_get_maxconnections(); - pollfd_list.pollfds = calloc(sizeof(struct pollfd), MAXCONNECTIONS); + pollfd_list.pollfds = calloc(sizeof(struct pollfd), maxconn); - for (fd = 0; fd < MAXCONNECTIONS; fd++) + for (fd = 0; fd < maxconn; fd++) pollfd_list.pollfds[fd].fd = -1; pollfd_list.maxindex = 0; - pollfd_list.allocated = MAXCONNECTIONS; + pollfd_list.allocated = maxconn; } static inline void diff --git a/libcharybdis/select.c b/libcharybdis/select.c index 5108915ea..b673e0acd 100644 --- a/libcharybdis/select.c +++ b/libcharybdis/select.c @@ -22,16 +22,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: select.c 3229 2007-03-05 17:23:07Z nenolod $ + * $Id: select.c 3354 2007-04-03 09:21:31Z nenolod $ */ #include "config.h" #include "libcharybdis.h" -#if HARD_FDLIMIT_ >= FD_SETSIZE -#error HARD_FDLIMIT_ must be less than FD_SETSIZE(try using poll instead of select) -#endif /* * Note that this is only a single list - multiple lists is kinda pointless * under select because the list size is a function of the highest FD :-) diff --git a/src/ircd.c b/src/ircd.c index 0646555c4..4b3f17061 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -21,7 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: ircd.c 3251 2007-03-05 18:58:38Z nenolod $ + * $Id: ircd.c 3354 2007-04-03 09:21:31Z nenolod $ */ #include "stdinc.h" @@ -144,15 +144,6 @@ init_sys(void) if(!getrlimit(RLIMIT_FD_MAX, &limit)) { - if(limit.rlim_max < MAXCONNECTIONS) - { - fprintf(stderr, "ircd's bootstrap fd table is too big\n"); - fprintf(stderr, "Hard Limit: %ld bootstrap size: %d\n", - (long) limit.rlim_max, MAXCONNECTIONS); - fprintf(stderr, "Fix MAXCONNECTIONS\n"); - exit(-1); - } - limit.rlim_cur = limit.rlim_max; /* make soft limit the max */ if(setrlimit(RLIMIT_FD_MAX, &limit) == -1) { diff --git a/src/listener.c b/src/listener.c index 7ed9a695c..d261c904c 100644 --- a/src/listener.c +++ b/src/listener.c @@ -21,7 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: listener.c 1675 2006-06-15 22:32:23Z jilles $ + * $Id: listener.c 3354 2007-04-03 09:21:31Z nenolod $ */ #include "stdinc.h" @@ -194,7 +194,11 @@ inetport(listener_t *listener) } } - + /* + * At one point, we enforced a strange arbitrary limit here. + * We no longer do this, and just check if the fd is valid or not. + * -nenolod + */ if(fd == -1) { report_error("opening listener socket %s:%s", @@ -202,14 +206,7 @@ inetport(listener_t *listener) get_listener_name(listener), errno); return 0; } - else if((HARD_FDLIMIT - 10) < fd) - { - report_error("no more connections left for listener %s:%s", - get_listener_name(listener), - get_listener_name(listener), errno); - comm_close(fd); - return 0; - } + /* * XXX - we don't want to do all this crap for a listener * set_sock_opts(listener); @@ -488,14 +485,13 @@ static void accept_connection(int pfd, void *data) { static time_t last_oper_notice = 0; - struct irc_sockaddr_storage sai; socklen_t addrlen = sizeof(sai); int fd; listener_t *listener = data; - struct ConfItem *aconf; - char buf[BUFSIZE]; - + struct ConfItem *aconf; + char buf[BUFSIZE]; + s_assert(listener != NULL); if(listener == NULL) return; @@ -525,8 +521,9 @@ accept_connection(int pfd, void *data) /* * check for connection limit + * TBD: this is stupid... either we have a socket or we don't. -nenolod */ - if((MAXCONNECTIONS - 10) < fd) + if((comm_get_maxconnections() - 10) < fd) { ++ServerStats->is_ref; /* @@ -554,19 +551,19 @@ accept_connection(int pfd, void *data) { ServerStats->is_ref++; - if(ConfigFileEntry.dline_with_reason) - { - if (ircsnprintf(buf, sizeof(buf), "ERROR :*** Banned: %s\r\n", aconf->passwd) >= (sizeof(buf)-1)) - { - buf[sizeof(buf) - 3] = '\r'; - buf[sizeof(buf) - 2] = '\n'; - buf[sizeof(buf) - 1] = '\0'; - } - } - else - ircsprintf(buf, "ERROR :You have been D-lined.\r\n"); + if(ConfigFileEntry.dline_with_reason) + { + if (ircsnprintf(buf, sizeof(buf), "ERROR :*** Banned: %s\r\n", aconf->passwd) >= (sizeof(buf)-1)) + { + buf[sizeof(buf) - 3] = '\r'; + buf[sizeof(buf) - 2] = '\n'; + buf[sizeof(buf) - 1] = '\0'; + } + } + else + ircsprintf(buf, "ERROR :You have been D-lined.\r\n"); - write(fd, buf, strlen(buf)); + write(fd, buf, strlen(buf)); comm_close(fd); /* Re-register a new IO request for the next accept .. */ diff --git a/src/restart.c b/src/restart.c index cc831e4bb..147b5dc3f 100644 --- a/src/restart.c +++ b/src/restart.c @@ -21,7 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: restart.c 3249 2007-03-05 18:51:17Z nenolod $ + * $Id: restart.c 3354 2007-04-03 09:21:31Z nenolod $ */ #include "stdinc.h" @@ -55,6 +55,7 @@ void server_reboot(void) { int i; + int maxconn = comm_get_maxconnections(); sendto_realops_snomask(SNO_GENERAL, L_ALL, "Restarting server..."); @@ -69,7 +70,7 @@ server_reboot(void) * bah, for now, the program ain't coming back to here, so forcibly * close everything the "wrong" way for now, and just LEAVE... */ - for (i = 0; i < MAXCONNECTIONS; ++i) + for (i = 0; i < maxconn; ++i) close(i); unlink(pidFileName); diff --git a/src/s_auth.c b/src/s_auth.c index 6224aa615..aae2eb65f 100644 --- a/src/s_auth.c +++ b/src/s_auth.c @@ -21,7 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: s_auth.c 3161 2007-01-25 07:23:01Z nenolod $ */ + * $Id: s_auth.c 3354 2007-04-03 09:21:31Z nenolod $ */ /* * Changes: @@ -286,7 +286,11 @@ start_auth_query(struct AuthRequest *auth) ++ServerStats->is_abad; return 0; } - if((MAXCONNECTIONS - 10) < fd) + + /* + * TBD: this is a pointless arbitrary limit .. we either have a socket or not. -nenolod + */ + if((comm_get_maxconnections() - 10) < fd) { sendto_realops_snomask(SNO_GENERAL, L_ALL, "Can't allocate fd for auth on %s", diff --git a/src/s_conf.c b/src/s_conf.c index bb59cbfc7..8521776e6 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -21,7 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: s_conf.c 3271 2007-03-18 14:44:24Z jilles $ + * $Id: s_conf.c 3354 2007-04-03 09:21:31Z nenolod $ */ #include "stdinc.h" @@ -852,7 +852,7 @@ set_default_conf(void) ConfigFileEntry.reject_ban_time = 300; ConfigFileEntry.reject_duration = 120; - ServerInfo.max_clients = MAXCONNECTIONS; + ServerInfo.max_clients = comm_get_maxconnections(); } #undef YES diff --git a/src/s_serv.c b/src/s_serv.c index 8cadc515b..86b4bfe6a 100644 --- a/src/s_serv.c +++ b/src/s_serv.c @@ -21,7 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: s_serv.c 3233 2007-03-05 17:28:27Z nenolod $ + * $Id: s_serv.c 3354 2007-04-03 09:21:31Z nenolod $ */ #include "stdinc.h" @@ -1368,8 +1368,10 @@ fork_server(struct Client *server) goto fork_error; else if(ret == 0) { + int maxconn = comm_get_maxconnections(); + /* set our fds as non blocking and close everything else */ - for (i = 0; i < HARD_FDLIMIT; i++) + for (i = 0; i < maxconn; i++) {