From: Amos Jeffries Date: Fri, 15 Mar 2024 17:26:29 +0000 (+0000) Subject: Convert loadable_modules to SBufList (#1738) X-Git-Tag: SQUID_7_0_1~170 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c464a532ab78b6ea240afd3a8a7a2485080dde0;p=thirdparty%2Fsquid.git Convert loadable_modules to SBufList (#1738) no behaviour changes. --- diff --git a/src/LoadableModule.cc b/src/LoadableModule.cc index efaf8efcff..0291c0978c 100644 --- a/src/LoadableModule.cc +++ b/src/LoadableModule.cc @@ -14,7 +14,8 @@ // Note: We must use preprocessor instead of C ifs because if dlopen() // is seen by the static linker, the linker will complain. -LoadableModule::LoadableModule(const String &aName): theName(aName), theHandle(nullptr) +LoadableModule::LoadableModule(const SBuf &aName): + theName(aName) { // Initialise preloaded symbol lookup table. LTDL_SET_PRELOADED_SYMBOLS(); @@ -62,7 +63,7 @@ LoadableModule::unload() void * LoadableModule::openModule() { - return lt_dlopen(theName.termedBuf()); + return lt_dlopen(theName.c_str()); } bool diff --git a/src/LoadableModule.h b/src/LoadableModule.h index 3c24675815..8601b4984e 100644 --- a/src/LoadableModule.h +++ b/src/LoadableModule.h @@ -9,26 +9,26 @@ #ifndef SQUID_SRC_LOADABLEMODULE_H #define SQUID_SRC_LOADABLEMODULE_H -#include "SquidString.h" +#include "sbuf/SBuf.h" // wrapper for dlopen(3), libltdl, and friends class LoadableModule { public: - LoadableModule(const String &aName); + explicit LoadableModule(const SBuf &aName); ~LoadableModule(); // unloads if loaded bool loaded() const; - const String &name() const { return theName; } - const String &error() const { return theError; } + const auto &name() const { return theName; } + const auto &error() const { return theError; } void load(); // throws Texc void unload(); // throws Texc protected: - String theName; - String theError; - void *theHandle; + SBuf theName; + SBuf theError; + void *theHandle = nullptr; private: void *openModule(); diff --git a/src/LoadableModules.cc b/src/LoadableModules.cc index d3024d2b37..1a5258e372 100644 --- a/src/LoadableModules.cc +++ b/src/LoadableModules.cc @@ -8,17 +8,16 @@ #include "squid.h" #include "debug/Messages.h" -#include "debug/Stream.h" #include "LoadableModule.h" #include "LoadableModules.h" -#include "wordlist.h" +#include "sbuf/List.h" static void -LoadModule(const char *fname) +LoadModule(const SBuf &fname) { debugs(1, DBG_IMPORTANT, "Loading Squid module from '" << fname << "'"); - LoadableModule *m = new LoadableModule(fname); + const auto m = new LoadableModule(fname); m->load(); debugs(1, 2, "Loaded Squid module from '" << fname << "'"); @@ -26,11 +25,11 @@ LoadModule(const char *fname) } void -LoadableModulesConfigure(const wordlist *names) +LoadableModulesConfigure(const SBufList &names) { - int count = 0; - for (const wordlist *i = names; i; i = i->next, ++count) - LoadModule(i->key); - debugs(1, Important(25), "Squid plugin modules loaded: " << count); + for (const auto &name : names) { + LoadModule(name); + } + debugs(1, Important(25), "Squid plugin modules loaded: " << names.size()); } diff --git a/src/LoadableModules.h b/src/LoadableModules.h index 25e1624b4d..8cb7ef8028 100644 --- a/src/LoadableModules.h +++ b/src/LoadableModules.h @@ -9,11 +9,13 @@ #ifndef SQUID_SRC_LOADABLEMODULES_H #define SQUID_SRC_LOADABLEMODULES_H +#include "sbuf/forward.h" + // TODO: add reporting for cachemgr // TODO: add reconfiguration support -class wordlist; -void LoadableModulesConfigure(const wordlist *names); +/// dynamically load named libraries, in the listed order +void LoadableModulesConfigure(const SBufList &); #endif /* SQUID_SRC_LOADABLEMODULES_H */ diff --git a/src/SquidConfig.h b/src/SquidConfig.h index 83063220ad..8ac9a47b94 100644 --- a/src/SquidConfig.h +++ b/src/SquidConfig.h @@ -519,7 +519,7 @@ public: CpuAffinityMap *cpuAffinityMap; #if USE_LOADABLE_MODULES - wordlist *loadable_module_names; + SBufList loadable_module_names; #endif int client_ip_max_connections; diff --git a/src/cf.data.pre b/src/cf.data.pre index 644899e676..48e40882ab 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -9766,7 +9766,7 @@ ecap_service s2 respmod_precache ecap://filters.R.us/virusFilter config=/etc/vf. DOC_END NAME: loadable_modules -TYPE: wordlist +TYPE: SBufList IFDEF: USE_LOADABLE_MODULES LOC: Config.loadable_module_names DEFAULT: none