]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: fix a race in the negcache unit tests 12696/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 28 Mar 2023 14:32:41 +0000 (16:32 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 28 Mar 2023 14:32:41 +0000 (16:32 +0200)
pdns/recursordist/negcache.cc
pdns/recursordist/negcache.hh
pdns/recursordist/test-negcache_cc.cc

index 77cc3e3b8ddf989f3282665a61c8b449bf281a51..57ac811e130015492ce1b6d1327ad17259eee45e 100644 (file)
@@ -295,7 +295,7 @@ void NegCache::prune(size_t maxEntries)
  *
  * \param fp A pointer to an open FILE object
  */
-size_t NegCache::doDump(int fd, size_t maxCacheEntries)
+size_t NegCache::doDump(int fd, size_t maxCacheEntries, time_t now)
 {
   int newfd = dup(fd);
   if (newfd == -1) {
@@ -308,9 +308,6 @@ size_t NegCache::doDump(int fd, size_t maxCacheEntries)
   }
   fprintf(fp.get(), "; negcache dump follows\n;\n");
 
-  struct timeval now;
-  Utility::gettimeofday(&now, nullptr);
-
   size_t ret = 0;
 
   size_t shard = 0;
@@ -326,7 +323,7 @@ size_t NegCache::doDump(int fd, size_t maxCacheEntries)
     auto& sidx = m->d_map.get<SequenceTag>();
     for (const NegCacheEntry& ne : sidx) {
       ret++;
-      int64_t ttl = ne.d_ttd - now.tv_sec;
+      int64_t ttl = ne.d_ttd - now;
       fprintf(fp.get(), "%s %" PRId64 " IN %s VIA %s ; (%s) origttl=%" PRIu32 " ss=%hu\n", ne.d_name.toString().c_str(), ttl, ne.d_qtype.toString().c_str(), ne.d_auth.toString().c_str(), vStateToString(ne.d_validationState).c_str(), ne.d_orig_ttl, ne.d_servedStale);
       for (const auto& rec : ne.authoritySOA.records) {
         fprintf(fp.get(), "%s %" PRId64 " IN %s %s ; (%s)\n", rec.d_name.toString().c_str(), ttl, DNSRecordContent::NumberToType(rec.d_type).c_str(), rec.getContent()->getZoneRepresentation().c_str(), vStateToString(ne.d_validationState).c_str());
index 0d42afee1099384033f3ceb60fc67e70f8f0f129..f8e8ce0be50e6e03f3fc4b5933d30ed926a99773 100644 (file)
@@ -100,7 +100,7 @@ public:
   size_t count(const DNSName& qname, QType qtype);
   void prune(size_t maxEntries);
   void clear();
-  size_t doDump(int fd, size_t maxCacheEntries);
+  size_t doDump(int fd, size_t maxCacheEntries, time_t now = time(nullptr));
   size_t wipe(const DNSName& name, bool subtree = false);
   size_t wipeTyped(const DNSName& name, QType qtype);
   size_t size() const;
index c432005ad0fe52e6e29f8d1045af7e40ca43b4bc..96172d458faac144aa2ea88549b0b2d9f33dbb70 100644 (file)
@@ -526,7 +526,7 @@ BOOST_AUTO_TEST_CASE(test_dumpToFile)
   if (!fp)
     BOOST_FAIL("Temporary file could not be opened");
 
-  cache.doDump(fileno(fp.get()), 0);
+  cache.doDump(fileno(fp.get()), 0, now.tv_sec);
 
   rewind(fp.get());
   char* line = nullptr;