From: Wouter Wijngaards Date: Wed, 9 May 2007 07:58:57 +0000 (+0000) Subject: Checks ulimit open files. X-Git-Tag: release-0.3~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=362a4f2e76fd2e04d791debcbbff3b8dfc9fd8d6;p=thirdparty%2Funbound.git Checks ulimit open files. git-svn-id: file:///svn/unbound/trunk@298 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/daemon/unbound.c b/daemon/unbound.c index fa6fc8474..3c2d3f8fd 100644 --- a/daemon/unbound.c +++ b/daemon/unbound.c @@ -45,10 +45,12 @@ #include "daemon/daemon.h" #include "util/config_file.h" #include "util/storage/slabhash.h" +#include "services/listen_dnsport.h" #include "util/data/msgreply.h" #include #include #include +#include /** print usage. */ static void usage() @@ -64,6 +66,40 @@ static void usage() printf("Report bugs to %s\n", PACKAGE_BUGREPORT); } +/** check file descriptor count */ +static void +checkrlimits(struct config_file* cfg) +{ + size_t list = ((cfg->do_ip4?1:0) + (cfg->do_ip6?1:0)) * + ((cfg->do_udp?1:0) + (cfg->do_tcp?1 + TCP_ACCEPT_COUNT:0)); + size_t ifs = (cfg->num_ifs==0?1:cfg->num_ifs); + size_t listen_num = list*ifs; + size_t outnum = cfg->outgoing_num_ports*ifs + cfg->outgoing_num_tcp; + size_t misc = 4; /* logfile, pidfile, stdout... */ + size_t perthread = listen_num + outnum + 2/*cmdpipe*/ + 2/*libevent*/ + + misc; +#if !defined(HAVE_PTHREAD) && !defined(HAVE_SOLARIS_THREADS) + size_t numthread = 1; /* it forks */ +#else + size_t numthread = cfg->num_threads; +#endif + size_t total = numthread * perthread + misc; + struct rlimit rlim; + if(getrlimit(RLIMIT_NOFILE, &rlim) < 0) { + log_warn("getrlimit: %s", strerror(errno)); + return; + } + if((size_t)rlim.rlim_cur < total) { + log_err("Not enough sockets available. Increase " + "ulimit(open files)."); + log_err("or decrease number of threads, outgoing num ports, " + "outgoing num tcp or number of interfaces"); + log_err("estimate %u fds high mark, %u available", + (unsigned)total, (unsigned)rlim.rlim_cur); + fatal_exit("Not enough file descriptors available"); + } +} + /** to changedir, logfile */ static void apply_dir(struct daemon* daemon, struct config_file* cfg, int cmdline_verbose) @@ -105,6 +141,7 @@ apply_dir(struct daemon* daemon, struct config_file* cfg, int cmdline_verbose) fatal_exit("malloc failure updating config settings"); } } + checkrlimits(cfg); } /** Read existing pid from pidfile. */ diff --git a/doc/Changelog b/doc/Changelog index 3f2b1fe19..8463c94d9 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -3,6 +3,7 @@ - fallback to TCP. - testbound replay with retry in TCP mode. - tpkg test for retry in TCP mode, against ldns-testns server. + - daemon checks max number of open files and complains if not enough. 8 May 2007: Wouter - outgoing network keeps list of available tcp buffers for outgoing diff --git a/services/listen_dnsport.c b/services/listen_dnsport.c index 52268647b..c996e16d3 100644 --- a/services/listen_dnsport.c +++ b/services/listen_dnsport.c @@ -54,8 +54,6 @@ /** number of queued TCP connections for listen() */ #define TCP_BACKLOG 5 -/** number of simultaneous open TCP connections for queries */ -#define TCP_COUNT 10 /** * Debug print of the getaddrinfo returned address. @@ -310,7 +308,7 @@ listen_create(struct comm_base* base, struct listen_port* ports, cp = comm_point_create_udp(base, ports->fd, front->udp_buff, cb, cb_arg); else cp = comm_point_create_tcp(base, ports->fd, - TCP_COUNT, bufsize, cb, cb_arg); + TCP_ACCEPT_COUNT, bufsize, cb, cb_arg); if(!cp) { log_err("can't create commpoint"); listen_delete(front); diff --git a/services/listen_dnsport.h b/services/listen_dnsport.h index 2dff15b56..b8e0f16e4 100644 --- a/services/listen_dnsport.h +++ b/services/listen_dnsport.h @@ -48,6 +48,9 @@ struct listen_list; struct addrinfo; struct config_file; +/** number of simultaneous open TCP connections for queries */ +#define TCP_ACCEPT_COUNT 10 + /** * Listening for queries structure. * Contains list of query-listen sockets.