From: Thomas Jarosch Date: Wed, 7 Apr 2021 10:05:36 +0000 (+0200) Subject: Write out cache file to temporary file + atomic replace X-Git-Url: http://developer.intra2net.com/git/?p=pingcheck;a=commitdiff_plain;h=ac0124576facc8e3d88b33e40ea09769b81a745f 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. --- 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);