mirror of
https://github.com/Icinga/icinga2.git
synced 2026-05-26 19:22:53 -04:00
Merge 275e466c59 into f63bbec4ab
This commit is contained in:
commit
2daa97ee8c
5 changed files with 30 additions and 0 deletions
|
|
@ -19,6 +19,12 @@ public:
|
|||
|
||||
static ActivationContext::Ptr GetCurrentContext();
|
||||
|
||||
static inline
|
||||
void AssertOnContext()
|
||||
{
|
||||
GetCurrentContext();
|
||||
}
|
||||
|
||||
private:
|
||||
static void PushContext(const ActivationContext::Ptr& context);
|
||||
static void PopContext();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-FileCopyrightText: 2012 Icinga GmbH <https://icinga.com>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "config/activationcontext.hpp"
|
||||
#include "config/applyrule.hpp"
|
||||
#include "base/logger.hpp"
|
||||
#include <set>
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include "config/configcompiler.hpp"
|
||||
#include "base/application.hpp"
|
||||
#include "base/configtype.hpp"
|
||||
#include "base/defer.hpp"
|
||||
#include "base/objectlock.hpp"
|
||||
#include "base/convert.hpp"
|
||||
#include "base/logger.hpp"
|
||||
|
|
@ -32,6 +33,8 @@
|
|||
using namespace icinga;
|
||||
|
||||
std::mutex ConfigItem::m_Mutex;
|
||||
thread_local bool ConfigItem::m_CommitInProgress = false;
|
||||
|
||||
ConfigItem::TypeMap ConfigItem::m_Items;
|
||||
ConfigItem::TypeMap ConfigItem::m_DefaultTemplates;
|
||||
ConfigItem::ItemList ConfigItem::m_UnnamedItems;
|
||||
|
|
@ -191,6 +194,9 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard)
|
|||
if (m_Scope)
|
||||
m_Scope->CopyTo(frame.Locals);
|
||||
try {
|
||||
m_CommitInProgress = true;
|
||||
Defer resetCommitInProgress ([this]() { m_CommitInProgress = false; });
|
||||
|
||||
m_Expression->Evaluate(frame, &debugHints);
|
||||
} catch (const std::exception& ex) {
|
||||
if (m_IgnoreOnError) {
|
||||
|
|
|
|||
|
|
@ -64,6 +64,12 @@ public:
|
|||
|
||||
static void RemoveIgnoredItems(const String& allowedConfigPath);
|
||||
|
||||
static inline
|
||||
bool RunsInCommitContext()
|
||||
{
|
||||
return m_CommitInProgress;
|
||||
}
|
||||
|
||||
private:
|
||||
Type::Ptr m_Type; /**< The object type. */
|
||||
String m_Name; /**< The name. */
|
||||
|
|
@ -82,6 +88,7 @@ private:
|
|||
ConfigObject::Ptr m_Object;
|
||||
|
||||
static std::mutex m_Mutex;
|
||||
static thread_local bool m_CommitInProgress;
|
||||
|
||||
typedef std::map<String, ConfigItem::Ptr> ItemMap;
|
||||
typedef std::map<Type::Ptr, ItemMap> TypeMap;
|
||||
|
|
|
|||
|
|
@ -909,6 +909,11 @@ ExpressionResult ApplyExpression::DoEvaluate(ScriptFrame& frame, DebugHint*) con
|
|||
if (frame.Sandboxed)
|
||||
BOOST_THROW_EXCEPTION(ScriptError("Apply rules are not allowed in sandbox mode.", m_DebugInfo));
|
||||
|
||||
ActivationContext::AssertOnContext();
|
||||
|
||||
if (ConfigItem::RunsInCommitContext())
|
||||
BOOST_THROW_EXCEPTION(ScriptError("Nested objects are not allowed", m_DebugInfo));
|
||||
|
||||
ExpressionResult nameres = m_Name->Evaluate(frame);
|
||||
CHECK_RESULT(nameres);
|
||||
|
||||
|
|
@ -943,6 +948,11 @@ ExpressionResult ObjectExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhi
|
|||
if (frame.Sandboxed)
|
||||
BOOST_THROW_EXCEPTION(ScriptError("Object definitions are not allowed in sandbox mode.", m_DebugInfo));
|
||||
|
||||
ActivationContext::AssertOnContext();
|
||||
|
||||
if (ConfigItem::RunsInCommitContext())
|
||||
BOOST_THROW_EXCEPTION(ScriptError("Nested objects are not allowed", m_DebugInfo));
|
||||
|
||||
ExpressionResult typeres = m_Type->Evaluate(frame, dhint);
|
||||
CHECK_RESULT(typeres);
|
||||
Type::Ptr type = typeres.GetValue();
|
||||
|
|
|
|||
Loading…
Reference in a new issue