summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-12-08 22:03:45 +0100
committerMatthias Schiffer <matthias@gamezock.de>2008-12-08 22:03:45 +0100
commit60f1e0a3942adba1505a8d56064b3cc53834045d (patch)
treead144073779b0143e54fc1ea642b17be074a8547
parentad7ee8df8ac73ef7754ccf1d5fb442ec23c879f1 (diff)
downloadmad-60f1e0a3942adba1505a8d56064b3cc53834045d.tar
mad-60f1e0a3942adba1505a8d56064b3cc53834045d.zip
Kann jetzt mit preopen ge?ffnete Module laden
-rw-r--r--src/Common/ModuleManager.cpp46
-rw-r--r--src/Common/ModuleManager.h6
-rw-r--r--src/Makefile.am4
-rw-r--r--src/Makefile.in4
-rw-r--r--src/mad-core.cpp4
-rw-r--r--src/mad.cpp4
-rw-r--r--src/modules/Makefile.am3
-rw-r--r--src/modules/Makefile.in13
8 files changed, 57 insertions, 27 deletions
diff --git a/src/Common/ModuleManager.cpp b/src/Common/ModuleManager.cpp
index 2df1078..06732a4 100644
--- a/src/Common/ModuleManager.cpp
+++ b/src/Common/ModuleManager.cpp
@@ -22,14 +22,28 @@
#include "ConfigEntry.h"
#include "Logger.h"
+#include <iostream>
+
+
+extern const lt_dlsymlist lt_preloaded_symbols[];
+
+
namespace Mad {
namespace Common {
ModuleManager ModuleManager::moduleManager;
+int ModuleManager::preopenCallback(lt_dlhandle handle) {
+ moduleManager.modules.insert(std::make_pair(lt_dlgetinfo(handle)->name, std::make_pair(handle, false)));
+}
+
void ModuleManager::doInit() {
lt_dlinit();
+
+ lt_dlpreload_default(lt_preloaded_symbols);
+ lt_dlpreload(0);
+ lt_dlpreload_open("@PROGRAM@", &ModuleManager::preopenCallback);
}
void ModuleManager::doDeinit() {
@@ -55,32 +69,38 @@ bool ModuleManager::handleConfigEntry(const ConfigEntry &entry, bool handled) {
return false;
}
-bool ModuleManager::loadModule(const std::string &name) {
- lt_dlhandle handle = lt_dlopen(name.c_str());
+lt_dlhandle ModuleManager::loadModule(const std::string &name) {
+ std::map<std::string, std::pair<lt_dlhandle, bool> >::iterator mod = modules.find(name);
- if(!handle)
- return false;
+ if(mod == modules.end()) {
+ lt_dlhandle handle = lt_dlopen((name + ".la").c_str());
- void (*initFun)();
- initFun = (void(*)())lt_dlsym(handle, "init");
+ if(!handle)
+ return 0;
- if(initFun)
- (*initFun)();
+ mod = modules.insert(std::make_pair(lt_dlgetinfo(handle)->name, std::make_pair(handle, false))).first;
+ }
+ if(!mod->second.second) {
+ void (*initFun)() = (void(*)())lt_dlsym(mod->second.first, "init");
- modules.insert(std::make_pair(name, handle));
- moduleOrder.push(name);
+ if(initFun)
+ (*initFun)();
+
+ mod->second.second = true;
+ moduleOrder.push(name);
+ }
- return true;
+ return mod->second.first;
}
void ModuleManager::unloadModule(const std::string &name) {
void (*deinitFun)();
- deinitFun = (void(*)())lt_dlsym(modules[name], "deinit");
+ deinitFun = (void(*)())lt_dlsym(modules[name].first, "deinit");
if(deinitFun)
(*deinitFun)();
- lt_dlclose(modules[name]);
+ lt_dlclose(modules[name].first);
modules.erase(name);
}
diff --git a/src/Common/ModuleManager.h b/src/Common/ModuleManager.h
index e327f28..fa7316f 100644
--- a/src/Common/ModuleManager.h
+++ b/src/Common/ModuleManager.h
@@ -36,9 +36,11 @@ class ModuleManager : public Configurable, public Initializable {
private:
static ModuleManager moduleManager;
- std::map<std::string, lt_dlhandle> modules;
+ std::map<std::string, std::pair<lt_dlhandle, bool> > modules;
std::stack<std::string> moduleOrder;
+ static int preopenCallback(lt_dlhandle handle);
+
void unloadModule(const std::string &name);
protected:
@@ -48,7 +50,7 @@ class ModuleManager : public Configurable, public Initializable {
virtual bool handleConfigEntry(const ConfigEntry &entry, bool handled);
public:
- bool loadModule(const std::string &name);
+ lt_dlhandle loadModule(const std::string &name);
static ModuleManager* get() {
if(!moduleManager.isInitialized())
diff --git a/src/Makefile.am b/src/Makefile.am
index 36dddfb..09dbff6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,7 +5,7 @@ bin_PROGRAMS = mad madc mad-core
mad_SOURCES = mad.cpp
mad_LDADD = Daemon/libdaemon.la Common/libcommon.la Net/libnet.la \
$(sigc_LIBS) $(GnuTLS_LIBS) @LIBLTDL@
-mad_LDFLAGS = -export-dynamic -dlopen modules/SystemBackendPosix.la -dlopen modules/SystemBackendProc.la
+mad_LDFLAGS = -export-dynamic -dlpreopen modules/SystemBackendPosix.la -dlpreopen modules/SystemBackendProc.la
madc_SOURCES = madc.cpp
madc_LDADD = Client/libclient.la Common/libcommon.la Net/libnet.la \
@@ -14,4 +14,4 @@ madc_LDADD = Client/libclient.la Common/libcommon.la Net/libnet.la \
mad_core_SOURCES = mad-core.cpp
mad_core_LDADD = Core/libcore.la Common/libcommon.la Net/libnet.la \
$(sigc_LIBS) $(GnuTLS_LIBS) $(GSSAPI_LIBS) @LIBLTDL@
-mad_core_LDFLAGS = -export-dynamic -dlopen modules/SystemBackendPosix.la -dlopen modules/SystemBackendProc.la
+mad_core_LDFLAGS = -export-dynamic -dlpreopen modules/SystemBackendPosix.la -dlpreopen modules/SystemBackendProc.la
diff --git a/src/Makefile.in b/src/Makefile.in
index 22d0c21..ad973f9 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -239,7 +239,7 @@ mad_SOURCES = mad.cpp
mad_LDADD = Daemon/libdaemon.la Common/libcommon.la Net/libnet.la \
$(sigc_LIBS) $(GnuTLS_LIBS) @LIBLTDL@
-mad_LDFLAGS = -export-dynamic -dlopen modules/SystemBackendPosix.la -dlopen modules/SystemBackendProc.la
+mad_LDFLAGS = -export-dynamic -dlpreopen modules/SystemBackendPosix.la -dlpreopen modules/SystemBackendProc.la
madc_SOURCES = madc.cpp
madc_LDADD = Client/libclient.la Common/libcommon.la Net/libnet.la \
$(sigc_LIBS) $(GnuTLS_LIBS) $(READLINE_LIBS)
@@ -248,7 +248,7 @@ mad_core_SOURCES = mad-core.cpp
mad_core_LDADD = Core/libcore.la Common/libcommon.la Net/libnet.la \
$(sigc_LIBS) $(GnuTLS_LIBS) $(GSSAPI_LIBS) @LIBLTDL@
-mad_core_LDFLAGS = -export-dynamic -dlopen modules/SystemBackendPosix.la -dlopen modules/SystemBackendProc.la
+mad_core_LDFLAGS = -export-dynamic -dlpreopen modules/SystemBackendPosix.la -dlpreopen modules/SystemBackendProc.la
all: all-recursive
.SUFFIXES:
diff --git a/src/mad-core.cpp b/src/mad-core.cpp
index c5627cb..05051ad 100644
--- a/src/mad-core.cpp
+++ b/src/mad-core.cpp
@@ -40,8 +40,8 @@ int main() {
Common::ConfigManager::get()->loadFile("mad-core.conf");
Common::ConfigManager::get()->finish();
- Common::ModuleManager::get()->loadModule("SystemBackendPosix.la");
- Common::ModuleManager::get()->loadModule("SystemBackendProc.la");
+ Common::ModuleManager::get()->loadModule("SystemBackendPosix");
+ Common::ModuleManager::get()->loadModule("SystemBackendProc");
while(true)
Core::ConnectionManager::get()->run();
diff --git a/src/mad.cpp b/src/mad.cpp
index 1fed06d..ccf4625 100644
--- a/src/mad.cpp
+++ b/src/mad.cpp
@@ -51,8 +51,8 @@ int main() {
Common::RequestManager::get()->registerPacketType<Daemon::RequestHandlers::CommandRequestHandler>(Net::Packet::COMMAND_REBOOT);
Common::RequestManager::get()->registerPacketType<Daemon::RequestHandlers::CommandRequestHandler>(Net::Packet::COMMAND_SHUTDOWN);
- Common::ModuleManager::get()->loadModule("SystemBackendPosix.la");
- Common::ModuleManager::get()->loadModule("SystemBackendProc.la");
+ Common::ModuleManager::get()->loadModule("SystemBackendPosix");
+ Common::ModuleManager::get()->loadModule("SystemBackendProc");
Net::ClientConnection *connection = new Net::ClientConnection;
diff --git a/src/modules/Makefile.am b/src/modules/Makefile.am
index 18d8ad6..40e15cc 100644
--- a/src/modules/Makefile.am
+++ b/src/modules/Makefile.am
@@ -2,11 +2,12 @@ madlibdir = ${libdir}/mad
moddir = ${madlibdir}/modules
mod_LTLIBRARIES = SystemBackendPosix.la SystemBackendProc.la
-AM_LDFLAGS = -module -avoid-version -export-dynamic
SystemBackendPosix_la_SOURCES = SystemBackendPosix.cpp
SystemBackendPosix_la_LIBADD = $(sigc_LIBS)
+SystemBackendPosix_la_LDFLAGS = -module -avoid-version -export-dynamic -static -export-symbols-regex '^SystemBackendPosix_LTX_'
SystemBackendProc_la_SOURCES = SystemBackendProc.cpp
+SystemBackendProc_la_LDFLAGS = -module -avoid-version -export-dynamic -static -export-symbols-regex '^SystemBackendProc_LTX_'
noinst_HEADERS = SystemBackendPosix.h SystemBackendProc.h
diff --git a/src/modules/Makefile.in b/src/modules/Makefile.in
index 538ace6..bc464ef 100644
--- a/src/modules/Makefile.in
+++ b/src/modules/Makefile.in
@@ -60,9 +60,15 @@ am__DEPENDENCIES_1 =
SystemBackendPosix_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
am_SystemBackendPosix_la_OBJECTS = SystemBackendPosix.lo
SystemBackendPosix_la_OBJECTS = $(am_SystemBackendPosix_la_OBJECTS)
+SystemBackendPosix_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
+ $(CXXFLAGS) $(SystemBackendPosix_la_LDFLAGS) $(LDFLAGS) -o $@
SystemBackendProc_la_LIBADD =
am_SystemBackendProc_la_OBJECTS = SystemBackendProc.lo
SystemBackendProc_la_OBJECTS = $(am_SystemBackendProc_la_OBJECTS)
+SystemBackendProc_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
+ $(CXXFLAGS) $(SystemBackendProc_la_LDFLAGS) $(LDFLAGS) -o $@
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
am__depfiles_maybe = depfiles
@@ -223,10 +229,11 @@ top_srcdir = @top_srcdir@
madlibdir = ${libdir}/mad
moddir = ${madlibdir}/modules
mod_LTLIBRARIES = SystemBackendPosix.la SystemBackendProc.la
-AM_LDFLAGS = -module -avoid-version -export-dynamic
SystemBackendPosix_la_SOURCES = SystemBackendPosix.cpp
SystemBackendPosix_la_LIBADD = $(sigc_LIBS)
+SystemBackendPosix_la_LDFLAGS = -module -avoid-version -export-dynamic -static -export-symbols-regex '^SystemBackendPosix_LTX_'
SystemBackendProc_la_SOURCES = SystemBackendProc.cpp
+SystemBackendProc_la_LDFLAGS = -module -avoid-version -export-dynamic -static -export-symbols-regex '^SystemBackendProc_LTX_'
noinst_HEADERS = SystemBackendPosix.h SystemBackendProc.h
all: all-am
@@ -289,9 +296,9 @@ clean-modLTLIBRARIES:
rm -f "$${dir}/so_locations"; \
done
SystemBackendPosix.la: $(SystemBackendPosix_la_OBJECTS) $(SystemBackendPosix_la_DEPENDENCIES)
- $(CXXLINK) -rpath $(moddir) $(SystemBackendPosix_la_OBJECTS) $(SystemBackendPosix_la_LIBADD) $(LIBS)
+ $(SystemBackendPosix_la_LINK) -rpath $(moddir) $(SystemBackendPosix_la_OBJECTS) $(SystemBackendPosix_la_LIBADD) $(LIBS)
SystemBackendProc.la: $(SystemBackendProc_la_OBJECTS) $(SystemBackendProc_la_DEPENDENCIES)
- $(CXXLINK) -rpath $(moddir) $(SystemBackendProc_la_OBJECTS) $(SystemBackendProc_la_LIBADD) $(LIBS)
+ $(SystemBackendProc_la_LINK) -rpath $(moddir) $(SystemBackendProc_la_OBJECTS) $(SystemBackendProc_la_LIBADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)