[icinga-checkins] icinga.org: icinga2/master: Remove temporary icinga2.debug file in case the config validation fails

git at icinga.org git at icinga.org
Fri Aug 5 09:11:25 CEST 2016


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

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Fri Aug  5 09:09:20 2016 +0200

Remove temporary icinga2.debug file in case the config validation fails

fixes #12318

---

 lib/cli/daemonutility.cpp            |    8 ++++++--
 lib/config/configcompilercontext.cpp |   12 ++++++++++++
 lib/config/configcompilercontext.hpp |    1 +
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/lib/cli/daemonutility.cpp b/lib/cli/daemonutility.cpp
index a6fe455..4d45ce6 100644
--- a/lib/cli/daemonutility.cpp
+++ b/lib/cli/daemonutility.cpp
@@ -162,14 +162,18 @@ bool DaemonUtility::LoadConfigFiles(const std::vector<std::string>& configs,
 {
 	ActivationScope ascope;
 
-	if (!DaemonUtility::ValidateConfigFiles(configs, objectsFile))
+	if (!DaemonUtility::ValidateConfigFiles(configs, objectsFile)) {
+		ConfigCompilerContext::GetInstance()->CancelObjectsFile();
 		return false;
+	}
 
 	WorkQueue upq(25000, Application::GetConcurrency());
 	bool result = ConfigItem::CommitItems(ascope.GetContext(), upq, newItems);
 
-	if (!result)
+	if (!result) {
+		ConfigCompilerContext::GetInstance()->CancelObjectsFile();
 		return false;
+	}
 
 	ConfigCompilerContext::GetInstance()->FinishObjectsFile();
 	ScriptGlobal::WriteToFile(varsfile);
diff --git a/lib/config/configcompilercontext.cpp b/lib/config/configcompilercontext.cpp
index 901e00d..c006dce 100644
--- a/lib/config/configcompilercontext.cpp
+++ b/lib/config/configcompilercontext.cpp
@@ -58,6 +58,18 @@ void ConfigCompilerContext::WriteObject(const Dictionary::Ptr& object)
 	}
 }
 
+void ConfigCompilerContext::CancelObjectsFile(void)
+{
+	m_ObjectsFP->Close();
+	m_ObjectsFP.reset();
+
+#ifdef _WIN32
+	_unlink(m_ObjectsTempFile.CStr());
+#else /* _WIN32 */
+	unlink(m_ObjectsTempFile.CStr());
+#endif /* _WIN32 */
+}
+
 void ConfigCompilerContext::FinishObjectsFile(void)
 {
 	m_ObjectsFP->Close();
diff --git a/lib/config/configcompilercontext.hpp b/lib/config/configcompilercontext.hpp
index cd4f2b0..1e47211 100644
--- a/lib/config/configcompilercontext.hpp
+++ b/lib/config/configcompilercontext.hpp
@@ -36,6 +36,7 @@ class I2_CONFIG_API ConfigCompilerContext
 public:
 	void OpenObjectsFile(const String& filename);
 	void WriteObject(const Dictionary::Ptr& object);
+	void CancelObjectsFile(void);
 	void FinishObjectsFile(void);
 
 	static ConfigCompilerContext *GetInstance(void);



More information about the icinga-checkins mailing list