Gentoo Archives: gentoo-commits

From: "Sven Wegener (swegener)" <swegener@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in net-dns/pdns-recursor/files: pdns-recursor-3.5.3-fdlimit.patch
Date: Sun, 29 Jun 2014 18:52:01
Message-Id: 20140629185120.3E97D2004F@flycatcher.gentoo.org
1 swegener 14/06/29 18:51:20
2
3 Added: pdns-recursor-3.5.3-fdlimit.patch
4 Log:
5 Also patch 3.5.3 for bug #514946.
6
7 (Portage version: 2.2.10/cvs/Linux x86_64, signed Manifest commit with key 0x64D4CF24)
8
9 Revision Changes Path
10 1.1 net-dns/pdns-recursor/files/pdns-recursor-3.5.3-fdlimit.patch
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-dns/pdns-recursor/files/pdns-recursor-3.5.3-fdlimit.patch?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-dns/pdns-recursor/files/pdns-recursor-3.5.3-fdlimit.patch?rev=1.1&content-type=text/plain
14
15 Index: pdns-recursor-3.5.3-fdlimit.patch
16 ===================================================================
17 --- pdns-recursor-3.5.3/misc.cc
18 +++ pdns-recursor-3.5.3/misc.cc
19 @@ -22,6 +22,7 @@
20 #include <netdb.h>
21 #include <sys/time.h>
22 #include <time.h>
23 +#include <sys/resource.h>
24 #include <netinet/in.h>
25 #include <unistd.h>
26 #endif // WIN32
27 @@ -697,3 +698,22 @@
28 } while(!strchr(buffer, '\n'));
29 return true;
30 }
31 +
32 +unsigned int getFilenumLimit(bool hardOrSoft)
33 +{
34 + struct rlimit rlim;
35 + if(getrlimit(RLIMIT_NOFILE, &rlim) < 0)
36 + unixDie("Requesting number of available file descriptors");
37 + return hardOrSoft ? rlim.rlim_max : rlim.rlim_cur;
38 +}
39 +
40 +void setFilenumLimit(unsigned int lim)
41 +{
42 + struct rlimit rlim;
43 +
44 + if(getrlimit(RLIMIT_NOFILE, &rlim) < 0)
45 + unixDie("Requesting number of available file descriptors");
46 + rlim.rlim_cur=lim;
47 + if(setrlimit(RLIMIT_NOFILE, &rlim) < 0)
48 + unixDie("Setting number of available file descriptors");
49 +}
50 --- pdns-recursor-3.5.3/misc.hh
51 +++ pdns-recursor-3.5.3/misc.hh
52 @@ -445,4 +445,6 @@
53 regex_t d_preg;
54 };
55
56 +unsigned int getFilenumLimit(bool hardOrSoft=0);
57 +void setFilenumLimit(unsigned int lim);
58 #endif
59 --- pdns-recursor-3.5.3/pdns_recursor.cc
60 +++ pdns-recursor-3.5.3/pdns_recursor.cc
61 @@ -1740,7 +1740,21 @@
62
63 g_tcpTimeout=::arg().asNum("client-tcp-timeout");
64 g_maxTCPPerClient=::arg().asNum("max-tcp-per-client");
65 - g_maxMThreads=::arg().asNum("max-mthreads");
66 + g_maxMThreads=::arg().asNum("max-mthreads");
67 + unsigned int availFDs=getFilenumLimit();
68 + if(g_maxMThreads * g_numThreads > availFDs) {
69 + if(getFilenumLimit(true) >= g_maxMThreads * g_numThreads) {
70 + setFilenumLimit(g_maxMThreads * g_numThreads);
71 + L<<Logger::Warning<<"Raised soft limit on number of filedescriptors to "<<g_maxMThreads * g_numThreads<<" to match max-mthreads and threads settings"<<endl;
72 + }
73 + else {
74 + int newval = getFilenumLimit(true) / g_numThreads;
75 + L<<Logger::Warning<<"Insufficient number of filedescriptors available for max-mthreads*threads setting! ("<<availFDs<<" < "<<g_maxMThreads*g_numThreads<<"), reducing max-mthreads to "<<newval<<endl;
76 + g_maxMThreads = newval;
77 + }
78 +
79 +
80 + }
81
82 if(g_numThreads == 1) {
83 L<<Logger::Warning<<"Operating unthreaded"<<endl;