[icinga-checkins] icinga.org: icinga2/next: Make sure the name of the initial library ( libicinga) is not hard-coded.

git at icinga.org git at icinga.org
Mon Nov 4 15:34:28 CET 2013


Module: icinga2
Branch: next
Commit: a6b0233b75a3d19b5ef35f0c79d69140f1254821
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=a6b0233b75a3d19b5ef35f0c79d69140f1254821

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Mon Nov  4 15:28:21 2013 +0100

Make sure the name of the initial library (libicinga) is not hard-coded.

Refs #4959

---

 doc/4.2-global-variables.md      |    2 +-
 icinga-app/icinga.cpp            |   29 +++++++++++++++++++++++------
 lib/icinga/icingaapplication.cpp |    2 ++
 3 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/doc/4.2-global-variables.md b/doc/4.2-global-variables.md
index 5c92a60..247db3c 100644
--- a/doc/4.2-global-variables.md
+++ b/doc/4.2-global-variables.md
@@ -10,7 +10,7 @@ IcingaPkgDataDir          |**Read-only.** Contains the path of the package data
 IcingaStatePath           |**Read-write.** Contains the path of the Icinga 2 state file. Defaults to IcingaLocalStateDir + "/lib/icinga2/icinga2.state".
 IcingaPidPath             |**Read-write.** Contains the path of the Icinga 2 PID file. Defaults to IcingaLocalStateDir + "/run/icinga2/icinga2.pid".
 IcingaMacros              |**Read-write.** Contains a dictionary with global macros. Not set by default.
-ApplicationType           |**Read-write.** Contains the name of the Application type. Defaults to "IcingaApplication".
+ApplicationType           |**Read-write.** Contains the name of the Application type. Defaults to "icinga/IcingaApplication".
 IcingaEnableNotifications |**Read-write.** Whether notifications are globally enabled. Defaults to true.
 IcingaEnableEventHandlers |**Read-write.** Whether event handlers are globally enabled. Defaults to true.
 IcingaEnableFlapping      |**Read-write.** Whether flap detection is globally enabled. Defaults to true.
diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp
index 781fef8..c040969 100644
--- a/icinga-app/icinga.cpp
+++ b/icinga-app/icinga.cpp
@@ -44,7 +44,25 @@ namespace po = boost::program_options;
 
 static po::variables_map g_AppParams;
 
-static bool LoadConfigFiles(bool validateOnly)
+static String LoadAppType(const String& typeSpec)
+{
+	int index;
+
+	Log(LogInformation, "icinga-app", "Loading application type: " + typeSpec);
+
+	index = typeSpec.FindFirstOf('/');
+
+	if (index == String::NPos)
+		return typeSpec;
+
+	String library = typeSpec.SubStr(0, index);
+
+	(void) Utility::LoadExtensionLibrary(library);
+
+	return typeSpec.SubStr(index + 1);
+}
+
+static bool LoadConfigFiles(const String& appType, bool validateOnly)
 {
 	ConfigCompilerContext::GetInstance()->Reset();
 
@@ -58,7 +76,7 @@ static bool LoadConfigFiles(bool validateOnly)
 	}
 
 	ConfigItemBuilder::Ptr builder = boost::make_shared<ConfigItemBuilder>();
-	builder->SetType(Application::GetApplicationType());
+	builder->SetType(appType);
 	builder->SetName("application");
 	ConfigItem::Ptr item = builder->Compile();
 	item->Register();
@@ -177,7 +195,7 @@ int main(int argc, char **argv)
 	Application::DeclareLocalStateDir(ICINGA_LOCALSTATEDIR);
 	Application::DeclarePkgDataDir(ICINGA_PKGDATADIR);
 
-	Application::DeclareApplicationType("IcingaApplication");
+	Application::DeclareApplicationType("icinga/IcingaApplication");
 
 	po::options_description desc("Supported options");
 	desc.add_options()
@@ -311,8 +329,7 @@ int main(int argc, char **argv)
 
 	Log(LogInformation, "icinga-app", "Icinga application loader (version: " + Application::GetVersion() + ")");
 
-	(void) Utility::LoadExtensionLibrary("icinga");
-	(void) Utility::LoadExtensionLibrary("methods");
+	String appType = LoadAppType(Application::GetApplicationType());
 
 	if (g_AppParams.count("library")) {
 		BOOST_FOREACH(const String& libraryName, g_AppParams["library"].as<std::vector<String> >()) {
@@ -345,7 +362,7 @@ int main(int argc, char **argv)
 
 	bool validateOnly = g_AppParams.count("validate");
 
-	if (!LoadConfigFiles(validateOnly))
+	if (!LoadConfigFiles(appType, validateOnly))
 		return EXIT_FAILURE;
 
 	if (validateOnly) {
diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp
index f8e5675..eadcfc5 100644
--- a/lib/icinga/icingaapplication.cpp
+++ b/lib/icinga/icingaapplication.cpp
@@ -38,6 +38,8 @@ INITIALIZE_ONCE(IcingaApplication, &IcingaApplication::StaticInitialize);
 
 void IcingaApplication::StaticInitialize(void)
 {
+	(void) Utility::LoadExtensionLibrary("methods");
+
 	ScriptVariable::Set("IcingaEnableNotifications", true);
 	ScriptVariable::Set("IcingaEnableEventHandlers", true);
 	ScriptVariable::Set("IcingaEnableFlapping", true);





More information about the icinga-checkins mailing list