[icinga-checkins] icinga.org: icinga2/master: Handle I/ O errors while writing the Icinga state file more gracefully

git at icinga.org git at icinga.org
Tue Aug 9 12:31:56 CEST 2016


Module: icinga2
Branch: master
Commit: 4c7e2994a7a93cc975df46f63e8506f466d9b99a
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=4c7e2994a7a93cc975df46f63e8506f466d9b99a

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Tue Aug  9 10:59:08 2016 +0200

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

fixes #12334

---

 lib/base/configobject.cpp        |    1 +
 lib/icinga/icingaapplication.cpp |    1 +
 2 files changed, 2 insertions(+)

diff --git a/lib/base/configobject.cpp b/lib/base/configobject.cpp
index 7db364f..26cefec 100644
--- a/lib/base/configobject.cpp
+++ b/lib/base/configobject.cpp
@@ -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"));
diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp
index 46a4034..1b7e99c 100644
--- a/lib/icinga/icingaapplication.cpp
+++ b/lib/icinga/icingaapplication.cpp
@@ -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));



More information about the icinga-checkins mailing list