diff --git a/itl/command-nscp-local.conf b/itl/command-nscp-local.conf index b654922da..8498d68f8 100644 --- a/itl/command-nscp-local.conf +++ b/itl/command-nscp-local.conf @@ -1,7 +1,7 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ if (!globals.contains("NscpPath")) { - NscpPath = dirname(msi_get_component_path("{5C45463A-4AE9-4325-96DB-6E239C034F93}")) + globals.NscpPath = dirname(msi_get_component_path("{5C45463A-4AE9-4325-96DB-6E239C034F93}")) } object CheckCommand "nscp-local" { diff --git a/lib/config/expression.cpp b/lib/config/expression.cpp index 814a15304..b02f2b73c 100644 --- a/lib/config/expression.cpp +++ b/lib/config/expression.cpp @@ -552,6 +552,58 @@ ExpressionResult GetScopeExpression::DoEvaluate(ScriptFrame& frame, DebugHint *d VERIFY(!"Invalid scope."); } +static inline +void WarnOnImplicitlySetGlobalVar(const std::unique_ptr& setLhs, const Value& setLhsParent, CombinedSetOp setOp, const DebugInfo& debug) +{ + auto var (dynamic_cast(setLhs.get())); + + if (var && setLhsParent.IsObject()) { + auto ns (dynamic_pointer_cast(setLhsParent.Get())); + + if (ns && ns == ScriptGlobal::GetGlobals()) { + const char *opStr = nullptr; + + switch (setOp) { + case OpSetLiteral: + opStr = "="; + break; + case OpSetAdd: + opStr = "+="; + break; + case OpSetSubtract: + opStr = "-="; + break; + case OpSetMultiply: + opStr = "*="; + break; + case OpSetDivide: + opStr = "/="; + break; + case OpSetModulo: + opStr = "%="; + break; + case OpSetXor: + opStr = "^="; + break; + case OpSetBinaryAnd: + opStr = "&="; + break; + case OpSetBinaryOr: + opStr = "|="; + break; + default: + VERIFY(!"Invalid opcode."); + } + + auto varName (var->GetVariable()); + + Log(LogWarning, "config") + << "Global variable '" << varName << "' has been set implicitly via '" << varName << ' ' << opStr << " ...' " << debug << "." + " Please set it explicitly via 'globals." << varName << ' ' << opStr << " ...' instead."; + } + } +} + ExpressionResult SetExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const { if (frame.Sandboxed) @@ -610,6 +662,8 @@ ExpressionResult SetExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) delete psdhint; } + WarnOnImplicitlySetGlobalVar(m_Operand1, parent, m_Op, m_DebugInfo); + return Empty; }