From: Charles-Henri Bruyand Date: Tue, 13 Mar 2018 21:59:05 +0000 (+0000) Subject: Use RAII wrappers for locks and some cleaning following reviews X-Git-Tag: dnsdist-1.3.0~40^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bcf07d98e40d93b5ef3b368b2d8af1ea4b2746d0;p=thirdparty%2Fpdns.git Use RAII wrappers for locks and some cleaning following reviews --- diff --git a/pdns/stubresolver.cc b/pdns/stubresolver.cc index c07cd746af..c496caabaf 100644 --- a/pdns/stubresolver.cc +++ b/pdns/stubresolver.cc @@ -24,7 +24,7 @@ static vector s_resolversForStub; static pthread_mutex_t s_resolversForStubLock = PTHREAD_MUTEX_INITIALIZER; // /etc/resolv.conf last modification time -static auto s_localResolvConfMtime = 0; +static time_t s_localResolvConfMtime = 0; /* * Returns false if no resolvers are configured, while emitting a warning about this @@ -46,6 +46,7 @@ static void parseLocalResolvConf() ifstream ifs(LOCAL_RESOLV_CONF_PATH); struct stat st; string line; + Lock l(&s_resolversForStubLock); if(!ifs) return; @@ -53,7 +54,6 @@ static void parseLocalResolvConf() return ; s_localResolvConfMtime = st.st_mtime; - pthread_mutex_lock(&s_resolversForStubLock); s_resolversForStub.clear(); while(std::getline(ifs, line)) { boost::trim_right_if(line, is_any_of(" \r\n\x1a")); @@ -76,7 +76,6 @@ static void parseLocalResolvConf() } } } - pthread_mutex_unlock(&s_resolversForStubLock); } /* @@ -109,7 +108,7 @@ int stubDoResolve(const DNSName& qname, uint16_t qtype, vector& r struct stat st; if (stat(LOCAL_RESOLV_CONF_PATH, &st) != -1) { - if (st.st_mtime > s_localResolvConfMtime) { + if (st.st_mtime != s_localResolvConfMtime) { parseLocalResolvConf(); } }