1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
19 #include "inspircd_config.h"
29 #include "inspstring.h"
30 #include "helperfuncs.h"
32 #include <sys/types.h>
35 DLLManager::DLLManager(char *fname)
38 this->staticname[0] = '\0';
39 log(DEBUG,"Loading core-compiled module '%s'",fname);
40 for (int j = 0; modsyms[j].name; j++)
42 log(DEBUG,"Check %s",modsyms[j].name);
43 if (!strcmp(modsyms[j].name,fname))
45 log(DEBUG,"Found %s",fname);
46 strlcpy(this->staticname,fname,1020);
51 err = "Module is not statically compiled into the ircd";
53 // Copy the library to a temp location, this makes recompiles
54 // a little safer if the ircd is running at the time as the
55 // shared libraries are mmap()ed and not doing this causes
57 FILE* x = fopen(fname,"rb");
58 char tmpfile_template[255];
60 snprintf(tmpfile_template, 255, "/tmp/inspircd_file.so.%d.XXXXXXXXXX",getpid());
61 int fd = mkstemp(tmpfile_template);
64 int n = fread(buffer, 1, 65535, x);
69 // Try to open the library now and get any error message.
71 h = dlopen(tmpfile_template, RTLD_NOW );
72 err = (char*)dlerror();
77 DLLManager::~DLLManager()
80 // close the library if it isn't null
90 bool DLLManager::GetSymbol(initfunc* &v, char *sym_name)
92 log(DEBUG,"Symbol search...");
93 for (int j = 0; modsyms[j].name; j++)
95 if (!strcmp(this->staticname,modsyms[j].name))
97 log(DEBUG,"Loading symbol...");
103 err = "Module symbol missing from the core";
109 bool DLLManager::GetSymbol(void **v, char *sym_name)
111 // try extract a symbol from the library
112 // get any error message is there is any
116 *v = dlsym( h, sym_name );
117 err = (char*)dlerror();
131 DLLFactoryBase::DLLFactoryBase(char *fname, char *factory) : DLLManager(fname)
133 // try get the factory function if there is no error yet
140 GetSymbol( factory_func, factory ? factory : (char*)"init_module" );
142 GetSymbol( (void **)&factory_func, factory ? factory : (char*)"init_module" );
148 DLLFactoryBase::~DLLFactoryBase()