summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-08-24 04:58:48 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-08-24 04:58:48 +0200
commit959a0b1b38e45cf8c00a862be01a0bb05e599123 (patch)
tree9c70cbf7ffaf60d834974435edf085b941c93933
parent6f5574c0f60679cd278ca20f0c91d268ccf63927 (diff)
downloadabrt-959a0b1b38e45cf8c00a862be01a0bb05e599123.tar.gz
abrt-959a0b1b38e45cf8c00a862be01a0bb05e599123.tar.xz
abrt-959a0b1b38e45cf8c00a862be01a0bb05e599123.zip
eliminate class DynamicLybrary by folding it into class ABRTPlugin
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--src/Daemon/ABRTPlugin.cpp28
-rw-r--r--src/Daemon/ABRTPlugin.h8
-rw-r--r--src/Daemon/DynamicLibrary.cpp59
-rw-r--r--src/Daemon/DynamicLibrary.h62
-rw-r--r--src/Daemon/Makefile.am1
-rw-r--r--src/Daemon/PluginManager.cpp2
6 files changed, 21 insertions, 139 deletions
diff --git a/src/Daemon/ABRTPlugin.cpp b/src/Daemon/ABRTPlugin.cpp
index 20486a2d..e3f5fb8d 100644
--- a/src/Daemon/ABRTPlugin.cpp
+++ b/src/Daemon/ABRTPlugin.cpp
@@ -19,22 +19,28 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "abrtlib.h"
#include "ABRTPlugin.h"
+#include <dlfcn.h>
-CABRTPlugin::CABRTPlugin(const std::string& pLibPath) :
- m_pDynamicLibrary(NULL),
- m_pPluginInfo(NULL),
- m_pFnPluginNew(NULL)
+CABRTPlugin::CABRTPlugin(const char* pLibPath)
{
- m_pDynamicLibrary = new CDynamicLibrary(pLibPath);
- m_pPluginInfo = reinterpret_cast<typeof(m_pPluginInfo)>(m_pDynamicLibrary->FindSymbol("plugin_info"));
- m_pFnPluginNew = reinterpret_cast<typeof(m_pFnPluginNew)>(m_pDynamicLibrary->FindSymbol("plugin_new"));
+ /* All errors are fatal */
+ m_pHandle = dlopen(pLibPath, RTLD_NOW);
+ if (!m_pHandle)
+ error_msg_and_die("can't load '%s'", pLibPath);
+
+#define LOADSYM(fp, handle, name) do { \
+ fp = (typeof(fp)) (dlsym(handle, name)); \
+ if (!fp) \
+ error_msg_and_die("'%s' has no %s entry", pLibPath, name); \
+} while (0)
+
+ LOADSYM(m_pPluginInfo, m_pHandle, "plugin_info");
+ LOADSYM(m_pFnPluginNew, m_pHandle, "plugin_new");
}
CABRTPlugin::~CABRTPlugin()
{
- if (m_pDynamicLibrary != NULL)
- {
- delete m_pDynamicLibrary;
- }
+ dlclose(m_pHandle);
}
diff --git a/src/Daemon/ABRTPlugin.h b/src/Daemon/ABRTPlugin.h
index 2f3e83d1..3433ad06 100644
--- a/src/Daemon/ABRTPlugin.h
+++ b/src/Daemon/ABRTPlugin.h
@@ -24,7 +24,6 @@
#define ABRTPLUGIN_H_
#include <string>
-#include "DynamicLibrary.h"
#include "Plugin.h"
/**
@@ -34,10 +33,9 @@ class CABRTPlugin
{
private:
/**
- * A class containing library which contains plugin functionality.
- * @see DynamicLibrary.h
+ * dlopen'ed library
*/
- CDynamicLibrary* m_pDynamicLibrary;
+ void* m_pHandle;
/**
* A pointer to struc containing information about plugin.
*/
@@ -53,7 +51,7 @@ class CABRTPlugin
* The constructor loads a plugin
* @param pLibPath a path to a plugin
*/
- CABRTPlugin(const std::string& pLibPath);
+ CABRTPlugin(const char* pLibPath);
/**
* A destructor.
*/
diff --git a/src/Daemon/DynamicLibrary.cpp b/src/Daemon/DynamicLibrary.cpp
deleted file mode 100644
index ffb2a6e4..00000000
--- a/src/Daemon/DynamicLibrary.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- DynamicLybrary.cpp
-
- Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
- Copyright (C) 2009 RedHat inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include "DynamicLibrary.h"
-#include "ABRTException.h"
-#include <iostream>
-#include <dlfcn.h>
-
-CDynamicLibrary::CDynamicLibrary(const std::string& pPath) :
- m_pHandle(NULL)
-{
- Load(pPath);
-}
-
-CDynamicLibrary::~CDynamicLibrary()
-{
- if (m_pHandle != NULL)
- {
- dlclose(m_pHandle);
- m_pHandle = NULL;
- }
-}
-
-void CDynamicLibrary::Load(const std::string& pPath)
-{
- m_pHandle = dlopen(pPath.c_str(), RTLD_NOW);
- if (m_pHandle == NULL)
- {
- throw CABRTException(EXCEP_DL, "CDynamicLibrary::Load(): Cannot load " + pPath + " : " + std::string(dlerror()));
- }
-}
-
-void* CDynamicLibrary::FindSymbol(const std::string& pName)
-{
- void* sym = dlsym(m_pHandle, pName.c_str());
- if (sym == NULL)
- {
- throw CABRTException(EXCEP_DL, "CDynamicLibrary::Load(): Cannot find symbol '" + pName + "'");
- }
- return sym;
-}
diff --git a/src/Daemon/DynamicLibrary.h b/src/Daemon/DynamicLibrary.h
deleted file mode 100644
index f3a95f5d..00000000
--- a/src/Daemon/DynamicLibrary.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- DynamicLybrary.h - header file for dynamic lybrarby wraper. It uses libdl.
-
- Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
- Copyright (C) 2009 RedHat inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-
-#ifndef DYNAMICLIBRARYH_
-#define DYNAMICLIBRARYH_
-
-#include <string>
-
-/**
- * A class. It contains one dynamic library.
- */
-class CDynamicLibrary
-{
- private:
- /**
- * A pointer to library.
- */
- void* m_pHandle;
- /**
- * A method, which loads a library.
- * @param pPath A path to the library.
- */
- void Load(const std::string& pPath);
- public:
- /**
- * A constructor.
- * @param pPath A path to the library.
- */
- CDynamicLibrary(const std::string& pPath);
- /**
- * A destructor.
- */
- ~CDynamicLibrary();
- /**
- * A method, which tries to find a symbol in a library. If it successes
- * then a non-NULL pointer is returned, otherwise NULL is returned.
- * @param pName A symbol name.
- * @return A pointer where a symbol name is loaded.
- */
- void* FindSymbol(const std::string& pName);
-};
-
-#endif /*DYNAMICLIBRARYH_*/
diff --git a/src/Daemon/Makefile.am b/src/Daemon/Makefile.am
index fdc1d604..d36650ab 100644
--- a/src/Daemon/Makefile.am
+++ b/src/Daemon/Makefile.am
@@ -2,7 +2,6 @@ sbin_PROGRAMS = abrt
abrt_SOURCES = \
DBusServerProxy.h DBusServerProxy.cpp \
- DynamicLibrary.cpp DynamicLibrary.h \
ABRTPlugin.cpp ABRTPlugin.h \
PluginManager.cpp PluginManager.h \
MiddleWare.cpp MiddleWare.h \
diff --git a/src/Daemon/PluginManager.cpp b/src/Daemon/PluginManager.cpp
index 945d6b48..d63d9769 100644
--- a/src/Daemon/PluginManager.cpp
+++ b/src/Daemon/PluginManager.cpp
@@ -95,7 +95,7 @@ void CPluginManager::LoadPlugin(const std::string& pName)
try
{
std::string libPath = m_sPluginsLibDir + "/" + PLUGINS_LIB_PREFIX + pName + "." + PLUGINS_LIB_EXTENSION;
- abrtPlugin = new CABRTPlugin(libPath);
+ abrtPlugin = new CABRTPlugin(libPath.c_str());
if (abrtPlugin->GetMagicNumber() != PLUGINS_MAGIC_NUMBER ||
(abrtPlugin->GetType() < ANALYZER && abrtPlugin->GetType() > DATABASE))
{