From: Remi Gacogne Date: Mon, 18 Mar 2024 09:21:26 +0000 (+0100) Subject: rec: Switch to `pdns::UniqueFilePtr` X-Git-Tag: rec-5.1.0-alpha1~117^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=01807c646de1af252681794c48a71d7b95f58df8;p=thirdparty%2Fpdns.git rec: Switch to `pdns::UniqueFilePtr` --- diff --git a/pdns/recursordist/aggressive_nsec.cc b/pdns/recursordist/aggressive_nsec.cc index 9cd729a0b8..76d39ee021 100644 --- a/pdns/recursordist/aggressive_nsec.cc +++ b/pdns/recursordist/aggressive_nsec.cc @@ -914,7 +914,7 @@ bool AggressiveNSECCache::getDenial(time_t now, const DNSName& name, const QType return true; } -size_t AggressiveNSECCache::dumpToFile(std::unique_ptr& fp, const struct timeval& now) +size_t AggressiveNSECCache::dumpToFile(pdns::UniqueFilePtr& fp, const struct timeval& now) { size_t ret = 0; diff --git a/pdns/recursordist/aggressive_nsec.hh b/pdns/recursordist/aggressive_nsec.hh index 6c7dfbb709..75665df1f7 100644 --- a/pdns/recursordist/aggressive_nsec.hh +++ b/pdns/recursordist/aggressive_nsec.hh @@ -95,7 +95,7 @@ public: static bool isSmallCoveringNSEC3(const DNSName& owner, const std::string& nextHash); void prune(time_t now); - size_t dumpToFile(std::unique_ptr& fp, const struct timeval& now); + size_t dumpToFile(pdns::UniqueFilePtr& fp, const struct timeval& now); private: struct ZoneEntry diff --git a/pdns/recursordist/negcache.cc b/pdns/recursordist/negcache.cc index 5bea1a06b9..cdec13249b 100644 --- a/pdns/recursordist/negcache.cc +++ b/pdns/recursordist/negcache.cc @@ -286,7 +286,7 @@ size_t NegCache::doDump(int fd, size_t maxCacheEntries, time_t now) if (newfd == -1) { return 0; } - auto fp = std::unique_ptr(fdopen(newfd, "w"), fclose); + auto fp = pdns::UniqueFilePtr(fdopen(newfd, "w")); if (!fp) { close(newfd); return 0; diff --git a/pdns/recursordist/pdns_recursor.cc b/pdns/recursordist/pdns_recursor.cc index 56c9954643..068ae7a84f 100644 --- a/pdns/recursordist/pdns_recursor.cc +++ b/pdns/recursordist/pdns_recursor.cc @@ -867,7 +867,7 @@ static void dumpTrace(const string& trace, const timeval& timev) return; } setNonBlocking(traceFd); - auto filep = std::unique_ptr(fdopen(traceFd, "a"), &fclose); + auto filep = pdns::UniqueFilePtr(fdopen(traceFd, "a")); if (!filep) { int err = errno; SLOG(g_log << Logger::Error << "Could not write to trace file: " << stringerror(err) << endl, diff --git a/pdns/recursordist/rec_channel_rec.cc b/pdns/recursordist/rec_channel_rec.cc index 94f7ec453e..2e407cd0a1 100644 --- a/pdns/recursordist/rec_channel_rec.cc +++ b/pdns/recursordist/rec_channel_rec.cc @@ -326,7 +326,7 @@ static uint64_t dumpAggressiveNSECCache(int fd) if (newfd == -1) { return 0; } - auto fp = std::unique_ptr(fdopen(newfd, "w"), fclose); + auto fp = pdns::UniqueFilePtr(fdopen(newfd, "w")); if (!fp) { return 0; } @@ -480,7 +480,7 @@ static RecursorControlChannel::Answer doDumpRPZ(int s, T begin, T end) return {1, "No RPZ zone named " + zoneName + "\n"}; } - auto fp = std::unique_ptr(fdopen(fdw, "w"), fclose); + auto fp = pdns::UniqueFilePtr(fdopen(fdw, "w")); if (!fp) { int err = errno; return {1, "converting file descriptor: " + stringerror(err) + "\n"}; diff --git a/pdns/recursordist/recpacketcache.cc b/pdns/recursordist/recpacketcache.cc index c372ee1862..9005bb62f4 100644 --- a/pdns/recursordist/recpacketcache.cc +++ b/pdns/recursordist/recpacketcache.cc @@ -264,7 +264,7 @@ uint64_t RecursorPacketCache::doDump(int file) if (fdupped == -1) { return 0; } - auto filePtr = std::unique_ptr(fdopen(fdupped, "w"), fclose); + auto filePtr = pdns::UniqueFilePtr(fdopen(fdupped, "w")); if (!filePtr) { close(fdupped); return 0; diff --git a/pdns/recursordist/recursor_cache.cc b/pdns/recursordist/recursor_cache.cc index fd40434011..b888bf2ef1 100644 --- a/pdns/recursordist/recursor_cache.cc +++ b/pdns/recursordist/recursor_cache.cc @@ -777,7 +777,7 @@ uint64_t MemRecursorCache::doDump(int fileDesc, size_t maxCacheEntries) if (newfd == -1) { return 0; } - auto filePtr = std::unique_ptr(fdopen(newfd, "w"), fclose); + auto filePtr = pdns::UniqueFilePtr(fdopen(newfd, "w")); if (!filePtr) { // dup probably failed close(newfd); return 0; diff --git a/pdns/recursordist/reczones.cc b/pdns/recursordist/reczones.cc index fa763cd9ad..ced34549a8 100644 --- a/pdns/recursordist/reczones.cc +++ b/pdns/recursordist/reczones.cc @@ -361,7 +361,7 @@ static void processForwardZonesFile(shared_ptr& newMap, sh else { SLOG(g_log << Logger::Warning << "Reading zone forwarding information from '" << filename << "'" << endl, log->info(Logr::Notice, "Reading zone forwarding information", "file", Logging::Loggable(filename))); - auto filePtr = std::unique_ptr(fopen(filename.c_str(), "r"), fclose); + auto filePtr = pdns::UniqueFilePtr(fopen(filename.c_str(), "r")); if (!filePtr) { int err = errno; throw PDNSException("Error opening forward-zones-file '" + filename + "': " + stringerror(err)); @@ -508,7 +508,7 @@ static void processAllowNotifyForFile(shared_ptr& newSet, Logr::log else { SLOG(g_log << Logger::Warning << "Reading NOTIFY-allowed zones from '" << filename << "'" << endl, log->info(Logr::Notice, "Reading NOTIFY-allowed zones from file", "file", Logging::Loggable(filename))); - auto filePtr = std::unique_ptr(fopen(filename.c_str(), "r"), fclose); + auto filePtr = pdns::UniqueFilePtr(fopen(filename.c_str(), "r")); if (!filePtr) { throw PDNSException("Error opening allow-notify-for-file '" + filename + "': " + stringerror()); } diff --git a/pdns/recursordist/rpzloader.cc b/pdns/recursordist/rpzloader.cc index fcf04fd183..478631363e 100644 --- a/pdns/recursordist/rpzloader.cc +++ b/pdns/recursordist/rpzloader.cc @@ -388,7 +388,7 @@ static bool dumpZoneToDisk(Logr::log_t logger, const DNSName& zoneName, const st return false; } - auto filePtr = std::unique_ptr(fdopen(fileDesc, "w+"), fclose); + auto filePtr = pdns::UniqueFilePtr(fdopen(fileDesc, "w+")); if (!filePtr) { int err = errno; close(fileDesc); diff --git a/pdns/recursordist/settings/cxxsupport.cc b/pdns/recursordist/settings/cxxsupport.cc index 8a9e331ff5..81e064ab79 100644 --- a/pdns/recursordist/settings/cxxsupport.cc +++ b/pdns/recursordist/settings/cxxsupport.cc @@ -58,7 +58,7 @@ void pdns::settings::rec::oldStyleForwardsFileToBridgeStruct(const std::string& file, ::rust::Vec& vec) { - auto filePtr = std::unique_ptr(fopen(file.c_str(), "r"), fclose); + auto filePtr = pdns::UniqueFilePtr(fopen(file.c_str(), "r")); if (!filePtr) { throw PDNSException("Error opening forward-zones-file '" + file + "': " + stringerror()); } diff --git a/pdns/recursordist/syncres.cc b/pdns/recursordist/syncres.cc index f824f89432..282944f544 100644 --- a/pdns/recursordist/syncres.cc +++ b/pdns/recursordist/syncres.cc @@ -1162,7 +1162,7 @@ uint64_t SyncRes::doEDNSDump(int fileDesc) if (newfd == -1) { return 0; } - auto filePtr = std::unique_ptr(fdopen(newfd, "w"), fclose); + auto filePtr = pdns::UniqueFilePtr(fdopen(newfd, "w")); if (!filePtr) { close(newfd); return 0; @@ -1214,7 +1214,7 @@ uint64_t SyncRes::doDumpNSSpeeds(int fileDesc) if (newfd == -1) { return 0; } - auto filePtr = std::unique_ptr(fdopen(newfd, "w"), fclose); + auto filePtr = pdns::UniqueFilePtr(fdopen(newfd, "w")); if (!filePtr) { close(newfd); return 0; @@ -1295,7 +1295,7 @@ uint64_t SyncRes::doDumpThrottleMap(int fileDesc) if (newfd == -1) { return 0; } - auto filePtr = std::unique_ptr(fdopen(newfd, "w"), fclose); + auto filePtr = pdns::UniqueFilePtr(fdopen(newfd, "w")); if (!filePtr) { close(newfd); return 0; @@ -1342,7 +1342,7 @@ uint64_t SyncRes::doDumpFailedServers(int fileDesc) if (newfd == -1) { return 0; } - auto filePtr = std::unique_ptr(fdopen(newfd, "w"), fclose); + auto filePtr = pdns::UniqueFilePtr(fdopen(newfd, "w")); if (!filePtr) { close(newfd); return 0; @@ -1382,7 +1382,7 @@ uint64_t SyncRes::doDumpNonResolvingNS(int fileDesc) if (newfd == -1) { return 0; } - auto filePtr = std::unique_ptr(fdopen(newfd, "w"), fclose); + auto filePtr = pdns::UniqueFilePtr(fdopen(newfd, "w")); if (!filePtr) { close(newfd); return 0; @@ -1422,7 +1422,7 @@ uint64_t SyncRes::doDumpSavedParentNSSets(int fileDesc) if (newfd == -1) { return 0; } - auto filePtr = std::unique_ptr(fdopen(newfd, "w"), fclose); + auto filePtr = pdns::UniqueFilePtr(fdopen(newfd, "w")); if (!filePtr) { close(newfd); return 0; @@ -1467,7 +1467,7 @@ uint64_t SyncRes::doDumpDoTProbeMap(int fileDesc) if (newfd == -1) { return 0; } - auto filePtr = std::unique_ptr(fdopen(newfd, "w"), fclose); + auto filePtr = pdns::UniqueFilePtr(fdopen(newfd, "w")); if (!filePtr) { close(newfd); return 0; diff --git a/pdns/recursordist/test-aggressive_nsec_cc.cc b/pdns/recursordist/test-aggressive_nsec_cc.cc index 7290c73194..e15993c8a7 100644 --- a/pdns/recursordist/test-aggressive_nsec_cc.cc +++ b/pdns/recursordist/test-aggressive_nsec_cc.cc @@ -1265,7 +1265,7 @@ BOOST_AUTO_TEST_CASE(test_aggressive_nsec_dump) BOOST_CHECK_EQUAL(cache->getEntriesCount(), 3U); - auto filePtr = std::unique_ptr(tmpfile(), fclose); + auto filePtr = pdns::UniqueFilePtr(tmpfile()); if (!filePtr) { BOOST_FAIL("Temporary file could not be opened"); } diff --git a/pdns/recursordist/test-negcache_cc.cc b/pdns/recursordist/test-negcache_cc.cc index f6ce64c4a6..44834b6315 100644 --- a/pdns/recursordist/test-negcache_cc.cc +++ b/pdns/recursordist/test-negcache_cc.cc @@ -525,9 +525,10 @@ BOOST_AUTO_TEST_CASE(test_dumpToFile) cache.add(genNegCacheEntry(DNSName("www1.powerdns.com"), DNSName("powerdns.com"), now)); cache.add(genNegCacheEntry(DNSName("www2.powerdns.com"), DNSName("powerdns.com"), now)); - auto fp = std::unique_ptr(tmpfile(), fclose); - if (!fp) + auto fp = pdns::UniqueFilePtr(tmpfile()); + if (!fp) { BOOST_FAIL("Temporary file could not be opened"); + } cache.doDump(fileno(fp.get()), 0, now.tv_sec); diff --git a/pdns/recursordist/test-rpzloader_cc.cc b/pdns/recursordist/test-rpzloader_cc.cc index ba19c66ba2..d1a9bf42f8 100644 --- a/pdns/recursordist/test-rpzloader_cc.cc +++ b/pdns/recursordist/test-rpzloader_cc.cc @@ -45,7 +45,7 @@ static string makeFile(const string& lines) std::array temp{"/tmp/rpzXXXXXXXXXX"}; int fileDesc = mkstemp(temp.data()); BOOST_REQUIRE(fileDesc > 0); - auto filePtr = std::unique_ptr(fdopen(fileDesc, "w"), fclose); + auto filePtr = pdns::UniqueFilePtr(fdopen(fileDesc, "w")); BOOST_REQUIRE(filePtr); size_t written = fwrite(lines.data(), 1, lines.length(), filePtr.get()); BOOST_REQUIRE(written == lines.length()); diff --git a/pdns/recursordist/test-settings.cc b/pdns/recursordist/test-settings.cc index f94dbf6c1d..91cc367853 100644 --- a/pdns/recursordist/test-settings.cc +++ b/pdns/recursordist/test-settings.cc @@ -256,7 +256,7 @@ example1.com= 1.2.3.4, 5.6.7.8; 8.9.0.1 std::string temp("/tmp/test-settingsXXXXXXXXXX"); int fileDesc = mkstemp(temp.data()); BOOST_REQUIRE(fileDesc > 0); - auto filePtr = std::unique_ptr(fdopen(fileDesc, "w"), fclose); + auto filePtr = pdns::UniqueFilePtr(fdopen(fileDesc, "w")); BOOST_REQUIRE(filePtr != nullptr); size_t written = fwrite(fileContent.data(), 1, fileContent.length(), filePtr.get()); BOOST_REQUIRE(written == fileContent.length());