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

fixes #12318
This commit is contained in:
Gunnar Beutner 2016-08-05 09:09:20 +02:00
parent d0658c465b
commit 46f8c7eb59
3 changed files with 19 additions and 2 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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);