Handle I/O errors while writing the Icinga state file more gracefully

fixes #12334
This commit is contained in:
Gunnar Beutner 2016-08-09 10:59:08 +02:00
parent 1aac54f4bb
commit 4c7e2994a7
2 changed files with 2 additions and 0 deletions

View File

@ -487,6 +487,7 @@ void ConfigObject::DumpObjects(const String& filename, int attributeTypes)
std::fstream fp;
String tempFilename = Utility::CreateTempFile(filename + ".XXXXXX", 0600, fp);
fp.exceptions(std::ofstream::failbit | std::ofstream::badbit);
if (!fp)
BOOST_THROW_EXCEPTION(std::runtime_error("Could not open '" + tempFilename + "' file"));

View File

@ -176,6 +176,7 @@ void IcingaApplication::DumpModifiedAttributes(void)
std::fstream fp;
String tempFilename = Utility::CreateTempFile(path + ".XXXXXX", 0644, fp);
fp.exceptions(std::ofstream::failbit | std::ofstream::badbit);
ConfigObject::Ptr previousObject;
ConfigObject::DumpModifiedAttributes(boost::bind(&PersistModAttrHelper, boost::ref(fp), boost::ref(previousObject), _1, _2, _3));