diff options
author | Peter Powell <petpow@saberuk.com> | 2019-02-20 17:34:11 +0000 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2019-02-20 17:34:11 +0000 |
commit | fa83fac94ab7cb5e18a546858054f3910ef24235 (patch) | |
tree | a26ec8ad8640d5f4683c541d4aa0855052d14963 | |
parent | 20ef7d19f7b684ea34ff1cd96450744920ab4a65 (diff) |
Split reading module initialisation and configuration reading.
This allows modules to register services that other modules may
require to be available when reading the configuration.
-rw-r--r-- | src/modules.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/modules.cpp b/src/modules.cpp index 8538d086e..66f424dcb 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -467,6 +467,7 @@ void ModuleManager::LoadAll() std::map<std::string, ServiceList> servicemap; LoadCoreModules(servicemap); + // Step 1: load all of the modules. ConfigTagList tags = ServerInstance->Config->ConfTags("module"); for (ConfigIter i = tags.first; i != tags.second; ++i) { @@ -487,8 +488,7 @@ void ModuleManager::LoadAll() } } - ConfigStatus confstatus; - + // Step 2: initialize the modules and register their services. for (ModuleMap::const_iterator i = Modules.begin(); i != Modules.end(); ++i) { Module* mod = i->second; @@ -498,7 +498,6 @@ void ModuleManager::LoadAll() AttachAll(mod); AddServices(servicemap[i->first]); mod->init(); - mod->ReadConfig(confstatus); } catch (CoreException& modexcept) { @@ -510,6 +509,27 @@ void ModuleManager::LoadAll() } this->NewServices = NULL; + ConfigStatus confstatus; + + // Step 3: Read the configuration for the modules. This must be done as part of + // its own step so that services provided by modules can be registered before + // the configuration is read. + for (ModuleMap::const_iterator i = Modules.begin(); i != Modules.end(); ++i) + { + Module* mod = i->second; + try + { + ServerInstance->Logs->Log("MODULE", LOG_DEBUG, "Reading configuration for %s", i->first.c_str()); + mod->ReadConfig(confstatus); + } + catch (CoreException& modexcept) + { + LastModuleError = "Unable to read the configuration for " + mod->ModuleSourceFile + ": " + modexcept.GetReason(); + ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError); + std::cout << std::endl << "[" << con_red << "*" << con_reset << "] " << LastModuleError << std::endl << std::endl; + ServerInstance->Exit(EXIT_STATUS_CONFIG); + } + } if (!PrioritizeHooks()) ServerInstance->Exit(EXIT_STATUS_MODULE); |