diff --git a/include/ircd.h b/include/ircd.h index b04fa7ff..c5e04208 100644 --- a/include/ircd.h +++ b/include/ircd.h @@ -106,6 +106,7 @@ extern int ircd_ssl_ok; extern int ircd_zlib_ok; extern int maxconnections; +extern void rehash_ulimit(); void ircd_shutdown(const char *reason) __attribute__((noreturn)); #endif diff --git a/modules/m_rehash.c b/modules/m_rehash.c index 87e46243..cd287983 100644 --- a/modules/m_rehash.c +++ b/modules/m_rehash.c @@ -354,6 +354,7 @@ do_rehash(struct Client *source_p, const char *type) ilog(L_MAIN, "REHASH From %s[%s]", get_oper_name(source_p), source_p->sockhost); rehash(0); + rehash_ulimit(); remote_rehash_oper_p = NULL; } } diff --git a/src/ircd.c b/src/ircd.c index cda38209..d830b249 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -177,6 +177,35 @@ init_sys(void) maxconnections = MAXCONNECTIONS; } +void rehash_ulimit(void) +{ + #if defined(RLIMIT_NOFILE) && defined(HAVE_SYS_RESOURCE_H) + struct rlimit limit; + + if(!getrlimit(RLIMIT_NOFILE, &limit) && limit.rlim_cur != maxconnections) + { + if(limit.rlim_cur <= MAX_BUFFER) + { + fprintf(stderr, "ERROR: Shell FD limits are too low.\n"); + fprintf(stderr, "ERROR: charybdis reserves %d FDs, shell limits must be above this\n", MAX_BUFFER); + fprintf(stderr, "ERROR: keeping old limits\n"); + return; + } else if(limit.rlim_cur < maxconnections) + { + fprintf(stderr, "ERROR: ulimit decreased\n"); + fprintf(stderr, "ERROR: keeping old limits\n"); + return; + } + + maxconnections = limit.rlim_cur; + + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "Setting maxconnections to %d", maxconnections); + return; + } + #endif /* RLIMIT_FD_MAX */ +} + static int make_daemon(void) { @@ -245,6 +274,7 @@ check_rehash(void *unused) if(dorehash) { rehash(1); + rehash_ulimit(); dorehash = 0; }