mirror of
https://github.com/Icinga/icinga2.git
synced 2025-09-23 17:57:54 +02:00
parent
9abf482708
commit
924068ceb8
@ -7,6 +7,7 @@
|
|||||||
#include "config/configcompiler.hpp"
|
#include "config/configcompiler.hpp"
|
||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
#include "base/configtype.hpp"
|
#include "base/configtype.hpp"
|
||||||
|
#include "base/defer.hpp"
|
||||||
#include "base/objectlock.hpp"
|
#include "base/objectlock.hpp"
|
||||||
#include "base/convert.hpp"
|
#include "base/convert.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
@ -31,6 +32,8 @@
|
|||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
std::mutex ConfigItem::m_Mutex;
|
std::mutex ConfigItem::m_Mutex;
|
||||||
|
thread_local bool ConfigItem::m_CommitInProgress = false;
|
||||||
|
|
||||||
ConfigItem::TypeMap ConfigItem::m_Items;
|
ConfigItem::TypeMap ConfigItem::m_Items;
|
||||||
ConfigItem::TypeMap ConfigItem::m_DefaultTemplates;
|
ConfigItem::TypeMap ConfigItem::m_DefaultTemplates;
|
||||||
ConfigItem::ItemList ConfigItem::m_UnnamedItems;
|
ConfigItem::ItemList ConfigItem::m_UnnamedItems;
|
||||||
@ -190,6 +193,9 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard)
|
|||||||
if (m_Scope)
|
if (m_Scope)
|
||||||
m_Scope->CopyTo(frame.Locals);
|
m_Scope->CopyTo(frame.Locals);
|
||||||
try {
|
try {
|
||||||
|
m_CommitInProgress = true;
|
||||||
|
Defer resetCommitInProgress ([this]() { m_CommitInProgress = false; });
|
||||||
|
|
||||||
m_Expression->Evaluate(frame, &debugHints);
|
m_Expression->Evaluate(frame, &debugHints);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
if (m_IgnoreOnError) {
|
if (m_IgnoreOnError) {
|
||||||
|
@ -63,6 +63,12 @@ public:
|
|||||||
|
|
||||||
static void RemoveIgnoredItems(const String& allowedConfigPath);
|
static void RemoveIgnoredItems(const String& allowedConfigPath);
|
||||||
|
|
||||||
|
static inline
|
||||||
|
bool RunsInCommitContext()
|
||||||
|
{
|
||||||
|
return m_CommitInProgress;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Type::Ptr m_Type; /**< The object type. */
|
Type::Ptr m_Type; /**< The object type. */
|
||||||
String m_Name; /**< The name. */
|
String m_Name; /**< The name. */
|
||||||
@ -81,6 +87,7 @@ private:
|
|||||||
ConfigObject::Ptr m_Object;
|
ConfigObject::Ptr m_Object;
|
||||||
|
|
||||||
static std::mutex m_Mutex;
|
static std::mutex m_Mutex;
|
||||||
|
static thread_local bool m_CommitInProgress;
|
||||||
|
|
||||||
typedef std::map<String, ConfigItem::Ptr> ItemMap;
|
typedef std::map<String, ConfigItem::Ptr> ItemMap;
|
||||||
typedef std::map<Type::Ptr, ItemMap> TypeMap;
|
typedef std::map<Type::Ptr, ItemMap> TypeMap;
|
||||||
|
@ -912,6 +912,9 @@ ExpressionResult ApplyExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhin
|
|||||||
if (frame.Sandboxed)
|
if (frame.Sandboxed)
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Apply rules are not allowed in sandbox mode.", m_DebugInfo));
|
BOOST_THROW_EXCEPTION(ScriptError("Apply rules are not allowed in sandbox mode.", m_DebugInfo));
|
||||||
|
|
||||||
|
if (ConfigItem::RunsInCommitContext())
|
||||||
|
BOOST_THROW_EXCEPTION(ScriptError("Nested objects are not allowed", m_DebugInfo));
|
||||||
|
|
||||||
ExpressionResult nameres = m_Name->Evaluate(frame);
|
ExpressionResult nameres = m_Name->Evaluate(frame);
|
||||||
CHECK_RESULT(nameres);
|
CHECK_RESULT(nameres);
|
||||||
|
|
||||||
@ -935,6 +938,9 @@ ExpressionResult ObjectExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhi
|
|||||||
if (frame.Sandboxed)
|
if (frame.Sandboxed)
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Object definitions are not allowed in sandbox mode.", m_DebugInfo));
|
BOOST_THROW_EXCEPTION(ScriptError("Object definitions are not allowed in sandbox mode.", m_DebugInfo));
|
||||||
|
|
||||||
|
if (ConfigItem::RunsInCommitContext())
|
||||||
|
BOOST_THROW_EXCEPTION(ScriptError("Nested objects are not allowed", m_DebugInfo));
|
||||||
|
|
||||||
ExpressionResult typeres = m_Type->Evaluate(frame, dhint);
|
ExpressionResult typeres = m_Type->Evaluate(frame, dhint);
|
||||||
CHECK_RESULT(typeres);
|
CHECK_RESULT(typeres);
|
||||||
Type::Ptr type = typeres.GetValue();
|
Type::Ptr type = typeres.GetValue();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user