From 60f1e0a3942adba1505a8d56064b3cc53834045d Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 8 Dec 2008 22:03:45 +0100 Subject: Kann jetzt mit preopen ge?ffnete Module laden --- src/Common/ModuleManager.cpp | 46 +++++++++++++++++++++++++++++++------------- src/Common/ModuleManager.h | 6 ++++-- src/Makefile.am | 4 ++-- src/Makefile.in | 4 ++-- src/mad-core.cpp | 4 ++-- src/mad.cpp | 4 ++-- src/modules/Makefile.am | 3 ++- src/modules/Makefile.in | 13 ++++++++++--- 8 files changed, 57 insertions(+), 27 deletions(-) (limited to 'src') 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 + + +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 >::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 modules; + std::map > modules; std::stack 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(Net::Packet::COMMAND_REBOOT); Common::RequestManager::get()->registerPacketType(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) -- cgit v1.2.3