From 2a95d1dfabea56a51dc9e9ef142499f2291794d4 Mon Sep 17 00:00:00 2001 From: Bert Hubert Date: Mon, 26 Mar 2007 20:18:23 +0000 Subject: [PATCH] speedup for pdns_recursor, fix crashes of BIND backend, fix filedescriptor leak in BIND backend git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@999 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- pdns/Makefile-recursor | 2 +- pdns/backends/bind/bindbackend2.cc | 13 ++++++++++--- pdns/backends/bind/bindbackend2.hh | 5 ++--- pdns/backends/bind/bindparser.hh | 11 ++++++++++- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/pdns/Makefile-recursor b/pdns/Makefile-recursor index 66aba1add..879760c13 100644 --- a/pdns/Makefile-recursor +++ b/pdns/Makefile-recursor @@ -3,7 +3,7 @@ SBINDIR=/usr/sbin/ BINDIR=/usr/bin/ CONFIGDIR="/etc/powerdns/" OPTFLAGS?=-O3 -CXXFLAGS:= $(CXXFLAGS) -Wall $(OPTFLAGS) $(PROFILEFLAGS) +CXXFLAGS:= $(CXXFLAGS) -Wall -DBOOST_SP_DISABLE_THREADS $(OPTFLAGS) $(PROFILEFLAGS) CFLAGS:=$(CFLAGS) -Wall $(OPTFLAGS) $(PROFILEFLAGS) LINKCC=$(CXX) CC?=gcc diff --git a/pdns/backends/bind/bindbackend2.cc b/pdns/backends/bind/bindbackend2.cc index 560947947..e952bfbc4 100644 --- a/pdns/backends/bind/bindbackend2.cc +++ b/pdns/backends/bind/bindbackend2.cc @@ -454,7 +454,6 @@ Bind2Backend::Bind2Backend(const string &suffix) if(!s_first) { return; } - s_first=0; s_state = shared_ptr(new State); loadConfig(); @@ -466,6 +465,14 @@ Bind2Backend::Bind2Backend(const string &suffix) dl->registerFunc("BIND-LIST-REJECTS", &DLListRejectsHandler); } +Bind2Backend::~Bind2Backend() +{ + if(us==this) { + L<loadConfig(status); @@ -629,8 +636,8 @@ void Bind2Backend::loadConfig(string* status) vector diff2; set_difference(newnames.begin(), newnames.end(), oldnames.begin(), oldnames.end(), back_inserter(diff2)); newdomains=diff2.size(); - - s_state = staging; // and boy do we hope this is a threadsafe operation! + + s_state.swap(staging); // and boy do we hope this is a threadsafe operation! // report ostringstream msg; diff --git a/pdns/backends/bind/bindbackend2.hh b/pdns/backends/bind/bindbackend2.hh index 68acd0d1d..2fc6c4381 100644 --- a/pdns/backends/bind/bindbackend2.hh +++ b/pdns/backends/bind/bindbackend2.hh @@ -28,7 +28,6 @@ using namespace std; using namespace boost; - /** This struct is used within the Bind2Backend to store DNS information. It is almost identical to a DNSResourceRecord, but then a bit smaller and with different sorting rules, which make sure that the SOA record comes up front. */ @@ -90,11 +89,11 @@ class Bind2Backend : public DNSBackend { public: Bind2Backend(const string &suffix=""); //!< Makes our connection to the database. Calls exit(1) if it fails. + ~Bind2Backend(); void getUnfreshSlaveInfos(vector *unfreshDomains); void getUpdatedMasters(vector *changedDomains); bool getDomainInfo(const string &domain, DomainInfo &di); time_t getCtime(const string &fname); - void lookup(const QType &, const string &qdomain, DNSPacket *p=0, int zoneId=-1); bool list(const string &target, int id); @@ -114,7 +113,7 @@ public: typedef map name_id_map_t; typedef map id_zone_map_t; - struct State + struct State : public boost::noncopyable { name_id_map_t name_id_map; //!< convert a name to a domain id id_zone_map_t id_zone_map; diff --git a/pdns/backends/bind/bindparser.hh b/pdns/backends/bind/bindparser.hh index 8b130d09e..5ec661a68 100644 --- a/pdns/backends/bind/bindparser.hh +++ b/pdns/backends/bind/bindparser.hh @@ -38,16 +38,25 @@ public: }; extern const char *bind_directory; +extern FILE *yyin; class BindParser { public: - BindParser() : d_dir("."), d_verbose(false) + BindParser() : d_dir("."), d_verbose(false) { + yyin=0; extern int include_stack_ptr; include_stack_ptr=0; bind_directory=d_dir.c_str(); } + ~BindParser() + { + if(yyin) { + fclose(yyin); + yyin=0; + } + } void parse(const string &fname); void commit(BindDomainInfo DI); void setDirectory(const string &dir); -- 2.50.0