diff options
-rw-r--r-- | include/command_parse.h | 20 | ||||
-rw-r--r-- | src/command_parse.cpp | 20 |
2 files changed, 31 insertions, 9 deletions
diff --git a/include/command_parse.h b/include/command_parse.h index a9c1e26c8..a0d27be17 100644 --- a/include/command_parse.h +++ b/include/command_parse.h @@ -55,10 +55,20 @@ class CommandParser : public classbase */ void SetupCommandTable(); - void FindSym(void** v, void* h); + /** Finds the init_command symbol in a .so file + * @param v A function pointer to be initialized + * @param h A valid shared object handle + * @return True if the symbol could be found + */ + bool FindSym(void** v, void* h); + /** A list of core-implemented modes and their shared object handles + */ SharedObjectList RFCCommands; + /** Load a command from a shared object on disk. + * @param name The shared object to load (without path) + */ void LoadCommand(const char* name); public: @@ -66,6 +76,14 @@ class CommandParser : public classbase */ command_table cmdlist; + /** Reload a core command. + * This will only reload commands implemented by the core, + * to reload a modular command, you must reload that module. + * @param cmd The command to reload. This will cause the shared + * object which implements this command to be closed, and then reloaded. + * @return True if the command was reloaded, false if it could not be found + * or another error occured + */ bool ReloadCommand(const char* cmd); /** Default constructor. diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 83f4674c4..9b5dc5316 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -475,15 +475,16 @@ CommandParser::CommandParser(InspIRCd* Instance) : ServerInstance(Instance) this->SetupCommandTable(); } -void CommandParser::FindSym(void** v, void* h) +bool CommandParser::FindSym(void** v, void* h) { *v = dlsym(h, "init_command"); const char* err = dlerror(); if (err) { - printf("ERROR: %s\n",err); - exit(0); + ServerInstance->Log(SPARSE, "Error loading core command: %s\n", err); + return false; } + return true; } bool CommandParser::ReloadCommand(const char* cmd) @@ -542,13 +543,16 @@ void CommandParser::LoadCommand(const char* name) h = dlopen(filename, RTLD_NOW | RTLD_GLOBAL); if (!h) + { + ServerInstance->Log(SPARSE, "Error loading core command: %s", dlerror()); return; + } - this->FindSym((void **)&cmd_factory_func, h); - - command_t* newcommand = cmd_factory_func(ServerInstance); - - this->CreateCommand(newcommand, h); + if (this->FindSym((void **)&cmd_factory_func, h)) + { + command_t* newcommand = cmd_factory_func(ServerInstance); + this->CreateCommand(newcommand, h); + } } void CommandParser::SetupCommandTable() |