From: Otto Moerbeek Date: Mon, 9 Nov 2020 10:50:53 +0000 (+0100) Subject: Follow suggestion by @rgacogne and specify the timestamp for X-Git-Tag: dnsdist-1.6.0-alpha0~27^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F9639%2Fhead;p=thirdparty%2Fpdns.git Follow suggestion by @rgacogne and specify the timestamp for converting ttd to ttl as an arg in the negCache dump. --- diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index a192962a23..c074c81662 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -210,7 +210,10 @@ static uint64_t dumpNegCache(int fd) return 0; } fprintf(fp.get(), "; negcache dump follows\n;\n"); - return g_negCache->dumpToFile(fp.get()); + + struct timeval now; + Utility::gettimeofday(&now, nullptr); + return g_negCache->dumpToFile(fp.get(), now); } static uint64_t* pleaseDump(int fd) diff --git a/pdns/recursordist/negcache.cc b/pdns/recursordist/negcache.cc index a2e5036867..72c164b39d 100644 --- a/pdns/recursordist/negcache.cc +++ b/pdns/recursordist/negcache.cc @@ -253,11 +253,9 @@ void NegCache::prune(size_t maxEntries) * * \param fp A pointer to an open FILE object */ -size_t NegCache::dumpToFile(FILE* fp) const +size_t NegCache::dumpToFile(FILE* fp, const struct timeval& now) const { size_t ret = 0; - struct timeval now; - Utility::gettimeofday(&now, nullptr); for (const auto& m : d_maps) { const lock l(m); diff --git a/pdns/recursordist/negcache.hh b/pdns/recursordist/negcache.hh index 1618d5af72..e7bdf3fe83 100644 --- a/pdns/recursordist/negcache.hh +++ b/pdns/recursordist/negcache.hh @@ -75,7 +75,7 @@ public: size_t count(const DNSName& qname, const QType qtype) const; void prune(size_t maxEntries); void clear(); - size_t dumpToFile(FILE* fd) const; + size_t dumpToFile(FILE* fd, const struct timeval& now) const; size_t wipe(const DNSName& name, bool subtree = false); size_t size() const; diff --git a/pdns/recursordist/test-negcache_cc.cc b/pdns/recursordist/test-negcache_cc.cc index 6da6de4749..8c3b38b625 100644 --- a/pdns/recursordist/test-negcache_cc.cc +++ b/pdns/recursordist/test-negcache_cc.cc @@ -437,7 +437,7 @@ BOOST_AUTO_TEST_CASE(test_dumpToFile) if (!fp) BOOST_FAIL("Temporary file could not be opened"); - cache.dumpToFile(fp.get()); + cache.dumpToFile(fp.get(), now); rewind(fp.get()); char* line = nullptr; @@ -449,8 +449,7 @@ BOOST_AUTO_TEST_CASE(test_dumpToFile) if (read == -1) BOOST_FAIL("Unable to read a line from the temp file"); // The clock might have ticked so the 600 becomes 599 - auto pos = str.find("600"); - BOOST_CHECK(line == str || line == str.replace(pos, 3, "599")); + BOOST_CHECK(line == str); } /* getline() allocates a buffer when called with a nullptr,