From: Pieter Lexis Date: Wed, 16 May 2018 13:26:22 +0000 (+0200) Subject: ixfrdist: remove several global vars X-Git-Tag: dnsdist-1.3.1~84^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=592f52eb408f734795991bd3515d83700f47ebdd;p=pdns ixfrdist: remove several global vars --- diff --git a/pdns/ixfrdist.cc b/pdns/ixfrdist.cc index f07fcc14a..18b4d4dec 100644 --- a/pdns/ixfrdist.cc +++ b/pdns/ixfrdist.cc @@ -104,9 +104,6 @@ struct ixfrdistdomain_t { set masters; // A set so we can do multiple master addresses in the future }; -// For all the listen-sockets -FDMultiplexer* g_fdm; - // This contains the configuration for each domain map g_domainConfigs; @@ -122,17 +119,9 @@ std::mutex g_tcpRequestFDsMutex; using namespace boost::multi_index; namespace po = boost::program_options; -po::variables_map g_vm; -string g_workdir; bool g_exiting = false; -#define KEEP_DEFAULT 20 -uint16_t g_keep = KEEP_DEFAULT; - -#define AXFRTIMEOUT_DEFAULT 20 -uint16_t g_axfrTimeout = AXFRTIMEOUT_DEFAULT; - NetmaskGroup g_acl; void handleSignal(int signum) { @@ -155,8 +144,8 @@ bool sortSOA(uint32_t i, uint32_t j) { return rfc1982LessThan(i, j); } -void cleanUpDomain(const DNSName& domain) { - string dir = g_workdir + "/" + domain.toString(); +void cleanUpDomain(const DNSName& domain, const uint16_t& keep, const string& workdir) { + string dir = workdir + "/" + domain.toString(); DIR *dp; dp = opendir(dir.c_str()); if (dp == nullptr) { @@ -171,12 +160,12 @@ void cleanUpDomain(const DNSName& domain) { zoneVersions.push_back(std::stoi(d->d_name)); } closedir(dp); - g_log< guard(g_soas_mutex); - for (auto iter = zoneVersions.cbegin(); iter != zoneVersions.cend() - g_keep; ++iter) { + for (auto iter = zoneVersions.cbegin(); iter != zoneVersions.cend() - keep; ++iter) { string fname = dir + "/" + std::to_string(*iter); g_log< lastCheck; // Initialize the serials we have for (const auto &domainConfig : g_domainConfigs) { DNSName domain = domainConfig.first; lastCheck[domain] = 0; - string dir = g_workdir + "/" + domain.toString(); + string dir = workdir + "/" + domain.toString(); try { g_log< soa; { - string fname = g_workdir + "/" + domain.toString() + "/" + std::to_string(serial); + string fname = workdir + "/" + domain.toString() + "/" + std::to_string(serial); loadSOAFromDisk(domain, fname, soa); records_t records; if (soa != nullptr) { @@ -245,7 +234,7 @@ void updateThread() { if (soa != nullptr) { g_log<d_st.serial< sr; try { @@ -318,7 +307,7 @@ void updateThread() { records_t records; time_t t_start = time(nullptr); time_t axfr_now = time(nullptr); - while(axfr.getChunk(nop, &chunk, (axfr_now - t_start + g_axfrTimeout))) { + while(axfr.getChunk(nop, &chunk, (axfr_now - t_start + axfrTimeout))) { for(auto& dr : chunk) { if(dr.d_type == QType::TSIG) continue; @@ -330,7 +319,7 @@ void updateThread() { } } axfr_now = time(nullptr); - if (axfr_now - t_start > g_axfrTimeout) { + if (axfr_now - t_start > axfrTimeout) { throw PDNSException("Total AXFR time exceeded!"); } } @@ -349,7 +338,7 @@ void updateThread() { g_soas[domain].ixfrDiffs.push_back(diff); } // Clean up the diffs - while (g_soas[domain].ixfrDiffs.size() > g_keep) { + while (g_soas[domain].ixfrDiffs.size() > keep) { g_soas[domain].ixfrDiffs.erase(g_soas[domain].ixfrDiffs.begin()); } g_soas[domain].latestAXFR = records; @@ -361,7 +350,7 @@ void updateThread() { g_log<()<()<<"': "<()].masters = s; } - g_workdir = config["work-dir"].as(); - for (const auto &addr : config["acl"].as>()) { try { g_acl.addMask(addr); @@ -974,8 +962,8 @@ int main(int argc, char** argv) { } g_log<addReadFD(s, stype == SOCK_DGRAM ? handleUDPRequest : handleTCPRequest); + fdm->addReadFD(s, stype == SOCK_DGRAM ? handleUDPRequest : handleTCPRequest); allSockets.insert(s); } catch(runtime_error &e) { g_log<(), + config["keep"].as(), + config["axfr-timeout"].as()); vector tcpHandlers; tcpHandlers.reserve(config["tcp-in-threads"].as()); @@ -1085,7 +1076,7 @@ int main(int argc, char** argv) { struct timeval now; for(;;) { gettimeofday(&now, 0); - g_fdm->run(&now); + fdm->run(&now); if (g_exiting) { g_log<