summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgeniusdex geniusdex@31f1291d-b8d6-0310-a050-a5561fc1590b <geniusdex geniusdex@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864>2005-09-28 15:52:22 +0000
committergeniusdex geniusdex@31f1291d-b8d6-0310-a050-a5561fc1590b <geniusdex geniusdex@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864>2005-09-28 15:52:22 +0000
commit08c234b8508a45a575187cf0a4c6961843849a94 (patch)
tree0405af6a0bc4331fa4e4d051020db6c348d1c4e4 /src
parent0ea76ce21f8274bf45e07432fb432d5f07cb8f11 (diff)
BUILD : 1.7.11 (902) BUGS : NOTES : Changed how /os modload and /os modunload load/unload modules; they are now handled in a queue instead of using the mod_current_* variables
git-svn-id: svn://svn.anope.org/anope/trunk@902 31f1291d-b8d6-0310-a050-a5561fc1590b git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@648 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src')
-rw-r--r--src/core/os_modload.c11
-rw-r--r--src/core/os_modunload.c10
-rw-r--r--src/modules.c100
-rw-r--r--src/process.c20
4 files changed, 107 insertions, 34 deletions
diff --git a/src/core/os_modload.c b/src/core/os_modload.c
index 732d629f4..c8541bb23 100644
--- a/src/core/os_modload.c
+++ b/src/core/os_modload.c
@@ -76,21 +76,14 @@ void myOperServHelp(User * u)
int do_modload(User * u)
{
char *name;
- Module *m;
name = strtok(NULL, "");
if (!name) {
syntax_error(s_OperServ, u, "MODLOAD", OPER_MODULE_LOAD_SYNTAX);
return MOD_CONT;
}
- m = findModule(name);
- if (!m) {
- m = createModule(name);
- mod_current_module = m;
- mod_current_user = u;
- mod_current_op = 1;
- } else {
+ if (!queueModuleLoad(name, u))
notice_lang(s_OperServ, u, OPER_MODULE_LOAD_FAIL, name);
- }
+
return MOD_CONT;
}
diff --git a/src/core/os_modunload.c b/src/core/os_modunload.c
index 315c7a7c4..6bfb00595 100644
--- a/src/core/os_modunload.c
+++ b/src/core/os_modunload.c
@@ -75,7 +75,6 @@ void myOperServHelp(User * u)
int do_modunload(User * u)
{
char *name;
- Module *m;
name = strtok(NULL, "");
if (!name) {
@@ -83,13 +82,8 @@ int do_modunload(User * u)
OPER_MODULE_UNLOAD_SYNTAX);
return MOD_CONT;
}
- m = findModule(name);
- if (m) {
- mod_current_user = u;
- mod_current_module = m;
- mod_current_op = 2;
- } else {
+ if (!queueModuleUnload(name, u))
notice_lang(s_OperServ, u, OPER_MODULE_REMOVE_FAIL, name);
- }
+
return MOD_CONT;
}
diff --git a/src/modules.c b/src/modules.c
index d420bfa1a..1b2bc0966 100644
--- a/src/modules.c
+++ b/src/modules.c
@@ -53,9 +53,10 @@ ModuleHash *MODULE_HASH[MAX_CMD_HASH];
Module *mod_current_module;
char *mod_current_module_name = NULL;
char *mod_current_buffer = NULL;
-int mod_current_op;
User *mod_current_user;
ModuleCallBack *moduleCallBackHead = NULL;
+ModuleQueue *mod_operation_queue = NULL;
+
int displayCommand(Command * c);
int displayCommandFromHash(CommandHash * cmdTable[], char *name);
int displayMessageFromHashl(char *name);
@@ -2578,4 +2579,101 @@ void moduleDeleteLanguage(int langNumber)
mod_current_module->lang[langNumber].argc = 0;
}
+/**
+ * Enqueue a module operation (load/unload/reload)
+ * @param m Module to perform the operation on
+ * @param op Operation to perform on the module
+ * @param u User who requested the operation
+ **/
+void queueModuleOperation(Module *m, ModuleOperation op, User *u)
+{
+ ModuleQueue *qm;
+
+ qm = scalloc(1, sizeof(ModuleQueue));
+ qm->m = m;
+ qm->op = op;
+ qm->u = u;
+ qm->next = mod_operation_queue;
+ mod_operation_queue = qm;
+}
+
+/**
+ * Enqueue a module to load
+ * @param name Name of the module to load
+ * @param u User who requested the load
+ * @return 1 on success, 0 on error
+ **/
+int queueModuleLoad(char *name, User *u)
+{
+ Module *m;
+
+ if (!name || !u)
+ return 0;
+
+ if (findModule(name))
+ return 0;
+ m = createModule(name);
+ queueModuleOperation(m, MOD_OP_LOAD, u);
+
+ return 1;
+}
+
+/**
+ * Enqueue a module to unload
+ * @param name Name of the module to unload
+ * @param u User who requested the unload
+ * @return 1 on success, 0 on error
+ **/
+int queueModuleUnload(char *name, User *u)
+{
+ Module *m;
+
+ if (!name || !u)
+ return 0;
+
+ m = findModule(name);
+ if (!m)
+ return 0;
+ queueModuleOperation(m, MOD_OP_UNLOAD, u);
+
+ return 1;
+}
+
+/**
+ * Execute all queued module operations
+ **/
+void handleModuleOperationQueue(void)
+{
+ ModuleQueue *next;
+ int status;
+
+ if (!mod_operation_queue)
+ return;
+
+ while (mod_operation_queue) {
+ next = mod_operation_queue->next;
+
+ mod_current_module = mod_operation_queue->m;
+ mod_current_user = mod_operation_queue->u;
+
+ if (mod_operation_queue->op == MOD_OP_LOAD) {
+ alog("Trying to load module [%s]", mod_operation_queue->m->name);
+ status = loadModule(mod_operation_queue->m, mod_operation_queue->u);
+ alog("Module loading status: %d", status);
+ } else if (mod_operation_queue->op == MOD_OP_UNLOAD) {
+ alog("Trying to unload module [%s]", mod_operation_queue->m->name);
+ status = unloadModule(mod_operation_queue->m, mod_operation_queue->u);
+ alog("Module unloading status: %d", status);
+ }
+
+ /* Remove the ModuleQueue from memory */
+ free(mod_operation_queue);
+
+ mod_operation_queue = next;
+ }
+
+ mod_current_module = NULL;
+ mod_current_user = NULL;
+}
+
/* EOF */
diff --git a/src/process.c b/src/process.c
index 5f5f27a50..8bf1ebb9d 100644
--- a/src/process.c
+++ b/src/process.c
@@ -18,7 +18,6 @@
extern Module *mod_current_module;
extern char *mod_current_module_name;
extern User *mod_current_user;
-extern int mod_current_op;
extern char *mod_current_buffer;
/*************************************************************************/
/*************************************************************************/
@@ -285,21 +284,10 @@ void process()
if (debug)
alog("debug: unknown message from server (%s)", inbuf);
}
- if (mod_current_op == 1) {
- alog("trying to load [%s]", mod_current_module->name);
- alog("status: [%d]",
- loadModule(mod_current_module, mod_current_user));
- mod_current_module = NULL;
- mod_current_user = NULL;
- mod_current_op = 0;
- } else if (mod_current_op == 2) {
- alog("trying to unload [%s]", mod_current_module->name);
- alog("status: [%d]",
- unloadModule(mod_current_module, mod_current_user));
- mod_current_module = NULL;
- mod_current_user = NULL;
- mod_current_op = 0;
- }
+
+ /* Load/unload modules if needed */
+ handleModuleOperationQueue();
+
/* Free argument list we created */
free(av);
}