]> granicus.if.org Git - icinga2/commitdiff
Handle I/O errors while writing the Icinga state file more gracefully
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 9 Aug 2016 08:59:08 +0000 (10:59 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 9 Aug 2016 08:59:08 +0000 (10:59 +0200)
fixes #12334

lib/base/configobject.cpp
lib/icinga/icingaapplication.cpp

index 7db364fba99e3e792ac1484f305acd094cf3ee59..26cefeca17a0dd2fb2f8dca963549007b214fa82 100644 (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"));
index 46a403493abc02dbc8d450f07bfdb18cdc7e5d5c..1b7e99c6d9cf5c42a6bdea0d83ea330e32b7fed6 100644 (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));