summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/modules.h7
-rw-r--r--src/modmanager_dynamic.cpp1
-rw-r--r--src/modmanager_static.cpp1
-rw-r--r--src/modules.cpp4
4 files changed, 11 insertions, 2 deletions
diff --git a/include/modules.h b/include/modules.h
index e450233da..8aedaabdd 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -116,7 +116,7 @@ struct ModResult {
* and numerical comparisons in preprocessor macros if they wish to support
* multiple versions of InspIRCd in one file.
*/
-#define INSPIRCD_VERSION_API 4
+#define INSPIRCD_VERSION_API 5
/**
* This #define allows us to call a method in all
@@ -357,6 +357,11 @@ class CoreExport Module : public classbase, public usecountbase
*/
DLLManager* ModuleDLLManager;
+ /** If true, this module will be unloaded soon, further unload attempts will fail
+ * Value is used by the ModuleManager internally, you should not modify it
+ */
+ bool dying;
+
/** Default constructor.
* Creates a module class. Don't do any type of hook registration or checks
* for other modules here; do that in init().
diff --git a/src/modmanager_dynamic.cpp b/src/modmanager_dynamic.cpp
index dab1143ad..7dae49a18 100644
--- a/src/modmanager_dynamic.cpp
+++ b/src/modmanager_dynamic.cpp
@@ -66,6 +66,7 @@ bool ModuleManager::Load(const std::string& filename, bool defer)
{
newmod->ModuleSourceFile = filename;
newmod->ModuleDLLManager = newhandle;
+ newmod->dying = false;
Modules[filename] = newmod;
std::string version = newhandle->GetVersion();
if (defer)
diff --git a/src/modmanager_static.cpp b/src/modmanager_static.cpp
index d2a2f2c09..8f532ee80 100644
--- a/src/modmanager_static.cpp
+++ b/src/modmanager_static.cpp
@@ -93,6 +93,7 @@ bool ModuleManager::Load(const std::string& name, bool defer)
mod = (*it->second->init)();
mod->ModuleSourceFile = name;
mod->ModuleDLLManager = NULL;
+ mod->dying = false;
Modules[name] = mod;
if (defer)
{
diff --git a/src/modules.cpp b/src/modules.cpp
index 4e4d20c70..a7b3364ae 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -328,7 +328,7 @@ bool ModuleManager::CanUnload(Module* mod)
{
std::map<std::string, Module*>::iterator modfind = Modules.find(mod->ModuleSourceFile);
- if (modfind == Modules.end() || modfind->second != mod)
+ if ((modfind == Modules.end()) || (modfind->second != mod) || (mod->dying))
{
LastModuleError = "Module " + mod->ModuleSourceFile + " is not loaded, cannot unload it!";
ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
@@ -340,6 +340,8 @@ bool ModuleManager::CanUnload(Module* mod)
ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError);
return false;
}
+
+ mod->dying = true;
return true;
}