From ac0124576facc8e3d88b33e40ea09769b81a745f Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Wed, 7 Apr 2021 12:05:36 +0200 Subject: [PATCH] Write out cache file to temporary file + atomic replace Just in case multiple processes might race for the writeout. Actually seen in production as pingcheck currently seems to get restarted by connd for every new INTRACLIENT. --- src/dns/dnscache.cpp | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/src/dns/dnscache.cpp b/src/dns/dnscache.cpp index c097aea..0e9a270 100644 --- a/src/dns/dnscache.cpp +++ b/src/dns/dnscache.cpp @@ -26,6 +26,7 @@ #include #include #include // I2n::file_exists +#include #include #include #include @@ -137,7 +138,7 @@ void DnsCache::save_to_cachefile() std::string cache_save_time_str = boost::posix_time::to_iso_string( boost::posix_time::second_clock::universal_time() ); - std::ofstream ofs( CacheFile.c_str() ); + I2n::tmpofcopystream ofs( CacheFile.c_str() ); boost::archive::xml_oarchive oa(ofs); oa & BOOST_SERIALIZATION_NVP(IpCache); oa & BOOST_SERIALIZATION_NVP(CnameCache); -- 1.7.1