]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Checks ulimit open files.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Wed, 9 May 2007 07:58:57 +0000 (07:58 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Wed, 9 May 2007 07:58:57 +0000 (07:58 +0000)
git-svn-id: file:///svn/unbound/trunk@298 be551aaa-1e26-0410-a405-d3ace91eadb9

daemon/unbound.c
doc/Changelog
services/listen_dnsport.c
services/listen_dnsport.h

index fa6fc847439f64133d1f9438daadee3176889f35..3c2d3f8fda4817b7113b230688833fd15e97f575 100644 (file)
 #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. */
index 3f2b1fe19c494fe8a96246814ff0c40da4ebd96a..8463c94d998f462c1c1a4e4fca254011d2efbbb7 100644 (file)
@@ -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 
index 52268647ba119b28e58316a7fee313eb1b244b51..c996e16d3e89b3eaa14f9669091a3e543c3d990e 100644 (file)
@@ -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);
index 2dff15b56bf0f0decf529f162725bff4a7ed7011..b8e0f16e4404e6c6f36f7c7909f346b4a34d8a4f 100644 (file)
@@ -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.