From d9a52277df06d656564b28e456adabbee52e8c10 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Tue, 31 Jul 2018 00:49:27 +0100 Subject: Remove support for static modules. This has been frequently broken in the past and as far as I know is used by literally nobody. Also, even if all modules are compiled into the core any libraries linked against are and have always been linked dynamically making this unusable on platforms without dynamic libraries. --- .travis.yml | 3 - include/modules.h | 23 ----- make/calcdep.pl | 55 +---------- make/template/main.mk | 11 --- make/unit-cc.pl | 36 +------- src/coremods/core_info/cmd_modules.cpp | 4 - src/modmanager_dynamic.cpp | 161 --------------------------------- src/modmanager_static.cpp | 148 ------------------------------ src/modulemanager.cpp | 157 ++++++++++++++++++++++++++++++++ tools/test-build | 16 +--- 10 files changed, 164 insertions(+), 450 deletions(-) delete mode 100644 src/modmanager_dynamic.cpp delete mode 100644 src/modmanager_static.cpp create mode 100644 src/modulemanager.cpp diff --git a/.travis.yml b/.travis.yml index f5c1fff54..204c5c086 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,6 @@ compiler: - clang - gcc dist: trusty -env: - - TEST_BUILD_DYNAMIC=1 - - TEST_BUILD_STATIC=1 language: cpp notifications: email: false diff --git a/include/modules.h b/include/modules.h index 0cdb73873..44cda7d19 100644 --- a/include/modules.h +++ b/include/modules.h @@ -1198,27 +1198,6 @@ class CoreExport ModuleManager : public fakederef #define MODULE_INIT_SYM_FN_2(x,y) MODULE_INIT_SYM_FN_1(x,y) #define MODULE_INIT_SYM_FN_1(x,y) inspircd_module_ ## x ## _ ## y -#ifdef INSPIRCD_STATIC - -struct AllCommandList { - typedef Command* (*fn)(Module*); - AllCommandList(fn cmd); -}; -#define COMMAND_INIT(x) static Command* MK_ ## x(Module* m) { return new x(m); } \ - static const AllCommandList PREP_ ## x(&MK_ ## x); - -struct AllModuleList { - typedef Module* (*fn)(); - fn init; - std::string name; - AllModuleList(fn mod, const std::string& Name); -}; - -#define MODULE_INIT(x) static Module* MK_ ## x() { return new x; } \ - static const AllModuleList PREP_ ## x(&MK_ ## x, MODNAME ".so"); - -#else - /** This definition is used as shorthand for the various classes * and functions needed to make a module loadable by the OS. * It defines the class factory and external init_module function. @@ -1231,5 +1210,3 @@ struct AllModuleList { extern "C" DllExport const char inspircd_src_version[] = INSPIRCD_VERSION; #define COMMAND_INIT(c) MODULE_INIT(CommandModule) - -#endif diff --git a/make/calcdep.pl b/make/calcdep.pl index f3ed04725..5dc0f6878 100755 --- a/make/calcdep.pl +++ b/make/calcdep.pl @@ -59,11 +59,7 @@ sub run() { open MAKE, '>real.mk' or die "Could not write real.mk: $!"; chdir "${\SOURCEPATH}/src"; - if ($ENV{INSPIRCD_STATIC}) { - run_static(); - } else { - run_dynamic(); - } + run_dynamic(); close MAKE; } @@ -133,56 +129,11 @@ modules: $mods END } -sub run_static() { - print MAKE <, , , , - , , "threadengines/threadengine_pthread.cpp") { - my $out = find_output $file, 1; - if ($out =~ m#obj/([^/]+)/[^/]+.o$#) { - mkdir "${\BUILDPATH}/obj/$1"; - } - dep_cpp $file, $out, 'gen-o'; - next if $file =~ m#^socketengines/# && $file ne "socketengines/socketengine_$ENV{SOCKETENGINE}.cpp"; - push @deps, $out; - push @srcs, $file; - } - - my $core_mk = join ' ', @deps; - my $core_src = join ' ', @srcs; - print MAKE < - -bin/inspircd: $core_mk obj/ld-extra.cmd - \@\$(SOURCEPATH)/make/unit-cc.pl static-ld \$\@ \$^ \$> - -inspircd: bin/inspircd - -.PHONY: all bad-target inspircd - -END -} - sub find_output { - my($file, $static) = @_; + my $file = shift; my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file"; if ($path eq 'modules/' || $path eq 'coremods/') { - return $static ? "obj/$base.o" : "modules/$base.so"; + return "modules/$base.so"; } elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) { return "obj/$base.o"; } elsif ($path =~ m#modules/(m_.*)/# || $path =~ m#coremods/(core_.*)/#) { diff --git a/make/template/main.mk b/make/template/main.mk index 447d64b3b..071e5da73 100644 --- a/make/template/main.mk +++ b/make/template/main.mk @@ -120,10 +120,6 @@ ifndef INSPIRCD_VERBOSE MAKEFLAGS += --silent endif -ifdef INSPIRCD_STATIC - CORECXXFLAGS += -DINSPIRCD_STATIC -endif - # Append any flags set in the environment after the base flags so # that they can be overridden if necessary. CORECXXFLAGS += $(CPPFLAGS) $(CXXFLAGS) @@ -134,7 +130,6 @@ export BUILDPATH export CORECXXFLAGS export CORELDFLAGS export CXX -export INSPIRCD_STATIC export INSPIRCD_VERBOSE export LDLIBS export PICLDFLAGS @@ -178,10 +173,6 @@ debug-header: @echo "*************************************" mod-header: -ifdef INSPIRCD_STATIC - @echo 'Cannot build specific targets in pure-static build' - @exit 1 -endif @echo 'Building specific targets:' mod-footer: target @@ -227,9 +218,7 @@ install: target @-$(INSTALL) -d -m $(INSTMODE_DIR) $(MODPATH) @-$(INSTALL) -d -m $(INSTMODE_DIR) $(SCRPATH) [ "$(BUILDPATH)/bin/" -ef $(BINPATH) ] || $(INSTALL) -m $(INSTMODE_BIN) "$(BUILDPATH)/bin/inspircd" $(BINPATH) -ifndef INSPIRCD_STATIC [ "$(BUILDPATH)/modules/" -ef $(MODPATH) ] || $(INSTALL) -m $(INSTMODE_LIB) "$(BUILDPATH)/modules/"*.so $(MODPATH) -endif -$(INSTALL) -m $(INSTMODE_BIN) @CONFIGURE_DIRECTORY@/inspircd $(SCRPATH) 2>/dev/null -$(INSTALL) -m $(INSTMODE_LIB) .gdbargs $(SCRPATH)/.gdbargs 2>/dev/null ifeq ($(SYSTEM), darwin) diff --git a/make/unit-cc.pl b/make/unit-cc.pl index 1cf6cf866..311c4c260 100755 --- a/make/unit-cc.pl +++ b/make/unit-cc.pl @@ -37,11 +37,7 @@ chdir $ENV{BUILDPATH}; my $type = shift; my $out = shift; -if ($type eq 'gen-ld') { - do_static_find(@ARGV); -} elsif ($type eq 'static-ld') { - do_static_link(@ARGV); -} elsif ($type eq 'core-ld') { +if ($type eq 'core-ld') { do_core_link(@ARGV); } elsif ($type eq 'link-dir') { do_link_dir(@ARGV); @@ -71,36 +67,6 @@ sub rpath($) { return $message; } -sub do_static_find { - my @flags; - for my $file (@ARGV) { - push @flags, rpath(get_directive($file, 'LinkerFlags', '')); - } - open F, '>', $out; - print F join ' ', @flags; - close F; - exit 0; -} - -sub do_static_link { - my $execstr = "$ENV{CXX} -o $out $ENV{CORELDFLAGS}"; - my $link_flags = ''; - for (@ARGV) { - if (/\.cmd$/) { - open F, '<', $_; - my $libs = ; - chomp $libs; - $link_flags .= ' '.$libs; - close F; - } else { - $execstr .= ' '.$_; - } - } - $execstr .= ' '.$ENV{LDLIBS}.' '.$link_flags; - message 'LINK', $out, $execstr; - exec $execstr; -} - sub do_core_link { my $execstr = "$ENV{CXX} -o $out $ENV{CORELDFLAGS} @_ $ENV{LDLIBS}"; message 'LINK', $out, $execstr; diff --git a/src/coremods/core_info/cmd_modules.cpp b/src/coremods/core_info/cmd_modules.cpp index 952b6bca2..7212e9525 100644 --- a/src/coremods/core_info/cmd_modules.cpp +++ b/src/coremods/core_info/cmd_modules.cpp @@ -71,12 +71,8 @@ CmdResult CommandModules::Handle(User* user, const Params& parameters) if (!(V.Flags & mult)) flags[pos] = '-'; -#ifdef INSPIRCD_STATIC - user->WriteRemoteNumeric(RPL_MODLIST, m->ModuleSourceFile, INSPIRCD_VERSION, flags, V.description); -#else std::string srcrev = m->ModuleDLLManager->GetVersion(); user->WriteRemoteNumeric(RPL_MODLIST, m->ModuleSourceFile, srcrev.empty() ? "*" : srcrev, flags, V.description); -#endif } else { diff --git a/src/modmanager_dynamic.cpp b/src/modmanager_dynamic.cpp deleted file mode 100644 index 644d2140f..000000000 --- a/src/modmanager_dynamic.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - * InspIRCd -- Internet Relay Chat Daemon - * - * Copyright (C) 2009-2010 Daniel De Graaf - * - * This file is part of InspIRCd. InspIRCd 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, version 2. - * - * 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, see . - */ - - -#include "inspircd.h" -#include "exitcodes.h" -#include - -#ifndef _WIN32 -#include -#endif - -#ifndef INSPIRCD_STATIC - -bool ModuleManager::Load(const std::string& modname, bool defer) -{ - /* Don't allow people to specify paths for modules, it doesn't work as expected */ - if (modname.find('/') != std::string::npos) - { - LastModuleError = "You can't load modules with a path: " + modname; - return false; - } - - const std::string filename = ExpandModName(modname); - const std::string moduleFile = ServerInstance->Config->Paths.PrependModule(filename); - - if (!FileSystem::FileExists(moduleFile)) - { - LastModuleError = "Module file could not be found: " + filename; - ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError); - return false; - } - - if (Modules.find(filename) != Modules.end()) - { - LastModuleError = "Module " + filename + " is already loaded, cannot load a module twice!"; - ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError); - return false; - } - - Module* newmod = NULL; - DLLManager* newhandle = new DLLManager(moduleFile.c_str()); - ServiceList newservices; - if (!defer) - this->NewServices = &newservices; - - try - { - newmod = newhandle->CallInit(); - this->NewServices = NULL; - - if (newmod) - { - newmod->ModuleSourceFile = filename; - newmod->ModuleDLLManager = newhandle; - newmod->dying = false; - Modules[filename] = newmod; - std::string version = newhandle->GetVersion(); - if (version.empty()) - version.assign("unknown"); - if (defer) - { - ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)", - filename.c_str(), version.c_str()); - } - else - { - ConfigStatus confstatus; - - AttachAll(newmod); - AddServices(newservices); - newmod->init(); - newmod->ReadConfig(confstatus); - - Version v = newmod->GetVersion(); - ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)%s", - filename.c_str(), version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]")); - } - } - else - { - LastModuleError = "Unable to load " + filename + ": " + newhandle->LastError(); - ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError); - delete newhandle; - return false; - } - } - catch (CoreException& modexcept) - { - this->NewServices = NULL; - - // failure in module constructor - if (newmod) - { - DoSafeUnload(newmod); - ServerInstance->GlobalCulls.AddItem(newhandle); - } - else - delete newhandle; - LastModuleError = "Unable to load " + filename + ": " + modexcept.GetReason(); - ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError); - return false; - } - - if (defer) - return true; - - FOREACH_MOD(OnLoadModule, (newmod)); - PrioritizeHooks(); - ServerInstance->ISupport.Build(); - return true; -} - -/* We must load the modules AFTER initializing the socket engine, now */ -void ModuleManager::LoadCoreModules(std::map& servicemap) -{ - std::cout << std::endl << "Loading core commands"; - fflush(stdout); - - DIR* library = opendir(ServerInstance->Config->Paths.Module.c_str()); - if (library) - { - dirent* entry = NULL; - while (0 != (entry = readdir(library))) - { - if (InspIRCd::Match(entry->d_name, "core_*.so", ascii_case_insensitive_map)) - { - std::cout << "."; - fflush(stdout); - - this->NewServices = &servicemap[entry->d_name]; - - if (!Load(entry->d_name, true)) - { - ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, this->LastError()); - std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << this->LastError() << std::endl << std::endl; - ServerInstance->Exit(EXIT_STATUS_MODULE); - } - } - } - closedir(library); - std::cout << std::endl; - } -} - -#endif diff --git a/src/modmanager_static.cpp b/src/modmanager_static.cpp deleted file mode 100644 index 4de111b63..000000000 --- a/src/modmanager_static.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/* - * InspIRCd -- Internet Relay Chat Daemon - * - * Copyright (C) 2009-2010 Daniel De Graaf - * - * This file is part of InspIRCd. InspIRCd 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, version 2. - * - * 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, see . - */ - - -#define MODNAME "core_all" - -#include "inspircd.h" -#include "exitcodes.h" -#include - -#ifdef INSPIRCD_STATIC - -typedef std::map modmap; -static std::vector* cmdlist = NULL; -static modmap* modlist = NULL; - -AllCommandList::AllCommandList(fn cmd) -{ - if (!cmdlist) - cmdlist = new std::vector(); - cmdlist->push_back(cmd); -} - -AllModuleList::AllModuleList(AllModuleList::fn mod, const std::string& Name) : init(mod), name(Name) -{ - if (!modlist) - modlist = new modmap(); - modlist->insert(std::make_pair(Name, this)); -} - -class AllModule : public Module -{ - std::vector cmds; - public: - AllModule() - { - if (!cmdlist) - return; - try - { - cmds.reserve(cmdlist->size()); - for(std::vector::iterator i = cmdlist->begin(); i != cmdlist->end(); ++i) - { - Command* c = (*i)(this); - cmds.push_back(c); - } - } - catch (...) - { - this->AllModule::~AllModule(); - throw; - } - } - - ~AllModule() - { - stdalgo::delete_all(cmds); - } - - Version GetVersion() CXX11_OVERRIDE - { - return Version("All commands", VF_VENDOR|VF_CORE); - } -}; - -MODULE_INIT(AllModule) - -bool ModuleManager::Load(const std::string& inputname, bool defer) -{ - const std::string name = ExpandModName(inputname); - modmap::iterator it = modlist->find(name); - if (it == modlist->end()) - return false; - Module* mod = NULL; - - ServiceList newservices; - if (!defer) - this->NewServices = &newservices; - - try - { - mod = (*it->second->init)(); - mod->ModuleSourceFile = name; - mod->ModuleDLLManager = NULL; - mod->dying = false; - Modules[name] = mod; - this->NewServices = NULL; - if (defer) - { - ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s", name.c_str()); - return true; - } - else - { - ConfigStatus confstatus; - - AttachAll(mod); - AddServices(newservices); - mod->init(); - mod->ReadConfig(confstatus); - } - } - catch (CoreException& modexcept) - { - this->NewServices = NULL; - - if (mod) - DoSafeUnload(mod); - ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Unable to load " + name + ": " + modexcept.GetReason()); - return false; - } - - FOREACH_MOD(OnLoadModule, (mod)); - PrioritizeHooks(); - ServerInstance->ISupport.Build(); - return true; -} - -void ModuleManager::LoadCoreModules(std::map& servicemap) -{ - for (modmap::const_iterator i = modlist->begin(); i != modlist->end(); ++i) - { - const std::string modname = i->first; - if (InspIRCd::Match(modname, "core_*.so", ascii_case_insensitive_map)) - { - this->NewServices = &servicemap[modname]; - Load(modname, true); - } - } - this->NewServices = NULL; -} - -#endif diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp new file mode 100644 index 000000000..eb40c5971 --- /dev/null +++ b/src/modulemanager.cpp @@ -0,0 +1,157 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2009-2010 Daniel De Graaf + * + * This file is part of InspIRCd. InspIRCd 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, version 2. + * + * 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, see . + */ + + +#include "inspircd.h" +#include "exitcodes.h" +#include + +#ifndef _WIN32 +#include +#endif + +bool ModuleManager::Load(const std::string& modname, bool defer) +{ + /* Don't allow people to specify paths for modules, it doesn't work as expected */ + if (modname.find('/') != std::string::npos) + { + LastModuleError = "You can't load modules with a path: " + modname; + return false; + } + + const std::string filename = ExpandModName(modname); + const std::string moduleFile = ServerInstance->Config->Paths.PrependModule(filename); + + if (!FileSystem::FileExists(moduleFile)) + { + LastModuleError = "Module file could not be found: " + filename; + ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError); + return false; + } + + if (Modules.find(filename) != Modules.end()) + { + LastModuleError = "Module " + filename + " is already loaded, cannot load a module twice!"; + ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError); + return false; + } + + Module* newmod = NULL; + DLLManager* newhandle = new DLLManager(moduleFile.c_str()); + ServiceList newservices; + if (!defer) + this->NewServices = &newservices; + + try + { + newmod = newhandle->CallInit(); + this->NewServices = NULL; + + if (newmod) + { + newmod->ModuleSourceFile = filename; + newmod->ModuleDLLManager = newhandle; + newmod->dying = false; + Modules[filename] = newmod; + std::string version = newhandle->GetVersion(); + if (version.empty()) + version.assign("unknown"); + if (defer) + { + ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)", + filename.c_str(), version.c_str()); + } + else + { + ConfigStatus confstatus; + + AttachAll(newmod); + AddServices(newservices); + newmod->init(); + newmod->ReadConfig(confstatus); + + Version v = newmod->GetVersion(); + ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s (Module version %s)%s", + filename.c_str(), version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]")); + } + } + else + { + LastModuleError = "Unable to load " + filename + ": " + newhandle->LastError(); + ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError); + delete newhandle; + return false; + } + } + catch (CoreException& modexcept) + { + this->NewServices = NULL; + + // failure in module constructor + if (newmod) + { + DoSafeUnload(newmod); + ServerInstance->GlobalCulls.AddItem(newhandle); + } + else + delete newhandle; + LastModuleError = "Unable to load " + filename + ": " + modexcept.GetReason(); + ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError); + return false; + } + + if (defer) + return true; + + FOREACH_MOD(OnLoadModule, (newmod)); + PrioritizeHooks(); + ServerInstance->ISupport.Build(); + return true; +} + +/* We must load the modules AFTER initializing the socket engine, now */ +void ModuleManager::LoadCoreModules(std::map& servicemap) +{ + std::cout << std::endl << "Loading core commands"; + fflush(stdout); + + DIR* library = opendir(ServerInstance->Config->Paths.Module.c_str()); + if (library) + { + dirent* entry = NULL; + while (0 != (entry = readdir(library))) + { + if (InspIRCd::Match(entry->d_name, "core_*.so", ascii_case_insensitive_map)) + { + std::cout << "."; + fflush(stdout); + + this->NewServices = &servicemap[entry->d_name]; + + if (!Load(entry->d_name, true)) + { + ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, this->LastError()); + std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << this->LastError() << std::endl << std::endl; + ServerInstance->Exit(EXIT_STATUS_MODULE); + } + } + } + closedir(library); + std::cout << std::endl; + } +} diff --git a/tools/test-build b/tools/test-build index c74dbb4e0..647289569 100755 --- a/tools/test-build +++ b/tools/test-build @@ -58,19 +58,9 @@ foreach my $compiler (@compilers) { say "Failed to configure using the $compiler compiler and the $socketengine socket engine!"; exit 1; } - if (!defined $ENV{TEST_BUILD_DYNAMIC}) { - $ENV{INSPIRCD_STATIC} = 1; - if (system 'make', '--jobs', get_cpu_count, 'install') { - say "Failed to compile with static modules using the $compiler compiler and the $socketengine socket engine!"; - exit 1; - } - } - if (!defined $ENV{TEST_BUILD_STATIC}) { - delete $ENV{INSPIRCD_STATIC}; - if (system 'make', '--jobs', get_cpu_count, 'install') { - say "Failed to compile with dynamic modules using the $compiler compiler and the $socketengine socket engine!"; - exit 1; - } + if (system 'make', '--jobs', get_cpu_count, 'install') { + say "Failed to compile using the $compiler compiler and the $socketengine socket engine!"; + exit 1; } say "Building using the $compiler compiler and the $socketengine socket engine succeeded!"; } -- cgit v1.2.3