From 115489a53197695aaad16ae3c46a26d0a1fbd7bf Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 2 Oct 2012 09:26:17 +0200 Subject: [PATCH] Fixed loading components when using a custom --libdir. --- configure.ac | 3 +++ icinga-app/icinga.cpp | 12 +++++------- lib/base/application.cpp | 27 +++++++++++++++++++++++++-- lib/base/application.h | 4 ++++ lib/base/component.cpp | 3 +++ 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index e7c1eb55e..e75ffb19f 100644 --- a/configure.ac +++ b/configure.ac @@ -72,6 +72,9 @@ AC_DEFINE_UNQUOTED([ICINGA_PREFIX], "$ICINGA_PREFIX", [The installation prefix.] AS_AC_EXPAND([ICINGA_LOCALSTATEDIR], $localstatedir) AC_DEFINE_UNQUOTED([ICINGA_LOCALSTATEDIR], "$ICINGA_LOCALSTATEDIR", [The local state dir.]) +AS_AC_EXPAND([ICINGA_PKGLIBDIR], $libdir/$PACKAGE_NAME) +AC_DEFINE_UNQUOTED([ICINGA_PKGLIBDIR], "$ICINGA_PKGLIBDIR", [The package lib dir.]) + AC_CONFIG_FILES([ Makefile components/Makefile diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 8a7e1ad3a..8402df55f 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -121,6 +121,10 @@ int main(int argc, char **argv) Application::SetLocalStateDir(ICINGA_LOCALSTATEDIR); #endif /* ICINGA_LOCALSTATEDIR */ +#ifdef ICINGA_PKGLIBDIR + Application::SetPkgLibDir(ICINGA_PKGLIBDIR); +#endif /* ICINGA_PKGLIBDIR */ + Logger::Write(LogInformation, "icinga", "Icinga application loader" #ifndef _WIN32 " (version: " ICINGA_VERSION ")" @@ -134,13 +138,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - String exeDirectory = Utility::DirName(Application::GetExePath(argv[0])); - Component::AddSearchDir(exeDirectory + "/../lib/icinga2"); - Component::AddSearchDir(exeDirectory + "/../lib64/icinga2"); - -#ifdef ICINGA_LIBDIR - Component::AddSearchDir(ICINGA_LIBDIR); -#endif /* ICINGA_LIBDIR */ + Component::AddSearchDir(Application::GetPkgLibDir()); try { DynamicObject::BeginTx(); diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 0ebdd92ad..42b72a421 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -31,6 +31,7 @@ bool Application::m_Debugging = false; boost::thread::id Application::m_MainThreadID; String Application::m_PrefixDir; String Application::m_LocalStateDir; +String Application::m_PkgLibDir; /** * Constructor for the Application class. @@ -408,7 +409,7 @@ void Application::ClosePidFile(void) String Application::GetPrefixDir(void) { if (m_PrefixDir.IsEmpty()) - return "./"; + return "."; else return m_PrefixDir; } @@ -431,7 +432,7 @@ void Application::SetPrefixDir(const String& path) String Application::GetLocalStateDir(void) { if (m_LocalStateDir.IsEmpty()) - return "./var/"; + return "./var"; else return m_LocalStateDir; } @@ -446,3 +447,25 @@ void Application::SetLocalStateDir(const String& path) m_LocalStateDir = path; } +/** + * Retrives the path for the package lib dir. + * + * @returns The path. + */ +String Application::GetPkgLibDir(void) +{ + if (m_PkgLibDir.IsEmpty()) + return "."; + else + return m_PkgLibDir; +} + +/** + * Sets the path for the package lib dir. + * + * @param path The new path. + */ +void Application::SetPkgLibDir(const String& path) +{ + m_PkgLibDir = path; +} diff --git a/lib/base/application.h b/lib/base/application.h index 390a7dc2f..ca7aef88b 100644 --- a/lib/base/application.h +++ b/lib/base/application.h @@ -68,6 +68,9 @@ public: static String GetLocalStateDir(void); static void SetLocalStateDir(const String& path); + static String GetPkgLibDir(void); + static void SetPkgLibDir(const String& path); + protected: void RunEventLoop(void); @@ -82,6 +85,7 @@ private: static boost::thread::id m_MainThreadID; /**< ID of the main thread. */ static String m_PrefixDir; /**< The installation prefix. */ static String m_LocalStateDir; /**< The local state dir. */ + static String m_PkgLibDir; /**< The package lib dir. */ #ifndef _WIN32 static void SigIntHandler(int signum); diff --git a/lib/base/component.cpp b/lib/base/component.cpp index e8c3950be..bc66042c6 100644 --- a/lib/base/component.cpp +++ b/lib/base/component.cpp @@ -123,6 +123,9 @@ void Component::Start(void) */ void Component::AddSearchDir(const String& componentDirectory) { + Logger::Write(LogInformation, "base", "Adding library search dir: " + + componentDirectory); + #ifdef _WIN32 SetDllDirectory(componentDirectory.CStr()); #else /* _WIN32 */ -- 2.40.0