summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dynamic.cpp55
-rw-r--r--src/inspircd.cpp23
-rw-r--r--src/modules/m_devoice.cpp5
3 files changed, 56 insertions, 27 deletions
diff --git a/src/dynamic.cpp b/src/dynamic.cpp
index 833f538ae..778a94521 100644
--- a/src/dynamic.cpp
+++ b/src/dynamic.cpp
@@ -64,12 +64,13 @@ DLLManager::DLLManager(const char *fname)
// a little safer if the ircd is running at the time as the
// shared libraries are mmap()ed and not doing this causes
// segfaults.
- FILE* x = fopen(fname,"rb");
+ /*FILE* x = fopen(fname,"rb");
if (!x)
{
err = strerror(errno);
return;
}
+ log(DEBUG,"Opened module file %s",fname);
char tmpfile_template[255];
char buffer[65536];
snprintf(tmpfile_template, 255, "%s/inspircd_file.so.%d.XXXXXXXXXX",Config->TempDir,getpid());
@@ -80,6 +81,7 @@ DLLManager::DLLManager(const char *fname)
err = strerror(errno);
return;
}
+ log(DEBUG,"Copying %s to %s",fname, tmpfile_template);
while (!feof(x))
{
int n = fread(buffer, 1, 65535, x);
@@ -94,26 +96,31 @@ DLLManager::DLLManager(const char *fname)
}
}
}
+ log(DEBUG,"Copied entire file.");
// Try to open the library now and get any error message.
-
- h = dlopen(tmpfile_template, RTLD_NOW );
+ if (close(fd) == -1)
+ err = strerror(errno);
+ if (fclose(x) == EOF)
+ err = strerror(errno);*/
+
+ h = dlopen(fname, RTLD_NOW|RTLD_LOCAL);
if (!h)
{
+ log(DEBUG,"dlerror occured!");
err = dlerror();
return;
}
- if (close(fd) == -1)
- err = strerror(errno);
- if (fclose(x) == EOF)
- err = strerror(errno);
+
+ /*log(DEBUG,"Finished loading '%s': %0x",tmpfile_template, h);
// We can delete the tempfile once it's loaded, leaving just the inode.
if (!err && !Config->debugging)
{
+ log(DEBUG,"Deleteting %s",tmpfile_template);
if (unlink(tmpfile_template) == -1)
err = strerror(errno);
- }
+ }*/
#endif
}
@@ -121,8 +128,8 @@ DLLManager::~DLLManager()
{
#ifndef STATIC_LINK
// close the library if it isn't null
- if (h != 0)
- dlclose(h);
+ if (h)
+ dlclose(h);
#endif
}
@@ -156,13 +163,26 @@ bool DLLManager::GetSymbol(void** v, const char* sym_name)
if (h)
{
- *v = dlsym(h, sym_name);
+ log(DEBUG,"Found symbol %s", sym_name);
+ dlerror(); // clear value
+ *v = dlsym(h, "init_module");
err = dlerror();
- return !err;
+
+ log(DEBUG,"%s",err);
+ if (!*v || err)
+ return false;
+
+ log(DEBUG,"%0x %0x",dlsym(h, "init_module"), *v);
+ }
+
+ if (err)
+ {
+ log(DEBUG,"Not found symbol");
+ return false;
}
else
{
- return false;
+ return true;
}
}
@@ -176,14 +196,17 @@ DLLFactoryBase::DLLFactoryBase(const char* fname, const char* factory) : DLLMana
if (!LastError())
{
#ifdef STATIC_LINK
- GetSymbol( factory_func, factory ? factory : "init_module" );
+ if (!GetSymbol( factory_func, factory ? factory : "init_module" ))
#else
- GetSymbol( (void **)&factory_func, factory ? factory : "init_module" );
+ if (!GetSymbol( (void **)&factory_func, factory ? factory : "init_module" ))
#endif
+ {
+ throw ModuleException("Missing init_module() entrypoint!");
+ }
}
}
-
DLLFactoryBase::~DLLFactoryBase()
{
}
+
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 3ce2261c5..79435ea58 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -586,18 +586,21 @@ bool InspIRCd::LoadModule(const char* filename)
return false;
}
}
- ircd_module* a = new ircd_module(modfile);
- factory[MODCOUNT+1] = a;
- if (factory[MODCOUNT+1]->LastError())
- {
- log(DEFAULT,"Unable to load %s: %s",modfile,factory[MODCOUNT+1]->LastError());
- snprintf(MODERR,MAXBUF,"Loader/Linker error: %s",factory[MODCOUNT+1]->LastError());
- return false;
- }
try
{
- if (factory[MODCOUNT+1]->factory)
+ ircd_module* a = new ircd_module(modfile);
+ log(DEBUG,"ircd_module constructor success, MODCOUNT %d",MODCOUNT);
+ factory[MODCOUNT+1] = a;
+ if (factory[MODCOUNT+1]->LastError())
+ {
+ log(DEFAULT,"Unable to load %s: %s",modfile,factory[MODCOUNT+1]->LastError());
+ snprintf(MODERR,MAXBUF,"Loader/Linker error: %s",factory[MODCOUNT+1]->LastError());
+ return false;
+ }
+ log(DEBUG,"No last error");
+ if ((int)factory[MODCOUNT+1]->factory != -1)
{
+ log(DEBUG,"Factory ptr: %0x",&factory[MODCOUNT+1]->factory);
Module* m = factory[MODCOUNT+1]->factory->CreateModule(MyServer);
modules[MODCOUNT+1] = m;
/* save the module and the module's classfactory, if
@@ -616,7 +619,7 @@ bool InspIRCd::LoadModule(const char* filename)
else
{
log(DEFAULT,"Unable to load %s",modfile);
- snprintf(MODERR,MAXBUF,"Factory function failed!");
+ snprintf(MODERR,MAXBUF,"Factory function failed: Probably missing init_module() entrypoint.");
return false;
}
}
diff --git a/src/modules/m_devoice.cpp b/src/modules/m_devoice.cpp
index 55b6abef7..713dc2788 100644
--- a/src/modules/m_devoice.cpp
+++ b/src/modules/m_devoice.cpp
@@ -26,6 +26,7 @@ using namespace std;
#include <stdio.h>
#include "users.h"
#include "channels.h"
+#include "helperfuncs.h"
#include "modules.h"
static Server *Srv;
@@ -62,6 +63,7 @@ class ModuleDeVoice : public Module
public:
ModuleDeVoice(Server* Me) : Module::Module(Me)
{
+ log(DEBUG,"ModuleDeVoice constructor");
Srv = Me;
mycommand = new cmd_devoice();
Srv->AddCommand(mycommand);
@@ -91,13 +93,14 @@ class ModuleDeVoiceFactory : public ModuleFactory
virtual Module * CreateModule(Server* Me)
{
+ log(DEBUG,"ModuleDevoiceFactory::CreateModule()");
return new ModuleDeVoice(Me);
}
};
-extern "C" void * module_init( void )
+extern "C" void * crud_u_like( void )
{
return new ModuleDeVoiceFactory;
}