]> granicus.if.org Git - icinga2/blob - lib/config/configfragment.hpp
Merge pull request #7113 from Elias481/fix/incorrect-usage-of-global-namespace-6874...
[icinga2] / lib / config / configfragment.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef CONFIGFRAGMENT_H
4 #define CONFIGFRAGMENT_H
5
6 #include "config/configcompiler.hpp"
7 #include "base/initialize.hpp"
8 #include "base/debug.hpp"
9 #include "base/exception.hpp"
10 #include "base/application.hpp"
11
12 /* Ensure that the priority is lower than the basic namespace initialization in scriptframe.cpp. */
13 #define REGISTER_CONFIG_FRAGMENT(name, fragment) \
14         INITIALIZE_ONCE_WITH_PRIORITY([]() { \
15                 std::unique_ptr<icinga::Expression> expression = icinga::ConfigCompiler::CompileText(name, fragment); \
16                 VERIFY(expression); \
17                 try { \
18                         icinga::ScriptFrame frame(true); \
19                         expression->Evaluate(frame); \
20                 } catch (const std::exception& ex) { \
21                         std::cerr << icinga::DiagnosticInformation(ex) << std::endl; \
22                         icinga::Application::Exit(1); \
23                 } \
24         }, 5)
25
26 #endif /* CONFIGFRAGMENT_H */