mirror of
https://github.com/NLnetLabs/unbound.git
synced 2026-01-02 04:49:34 -05:00
Checks ulimit open files.
git-svn-id: file:///svn/unbound/trunk@298 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
db0eccacb4
commit
362a4f2e76
4 changed files with 42 additions and 3 deletions
|
|
@ -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 <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
/** 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. */
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue