1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 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();
74 // We can delete the tempfile once it's loaded, leaving just the inode.
75 unlink(tmpfile_template);
79 DLLManager::~DLLManager()
82 // close the library if it isn't null
92 bool DLLManager::GetSymbol(initfunc* &v, char *sym_name)
94 log(DEBUG,"Symbol search...");
95 for (int j = 0; modsyms[j].name; j++)
97 if (!strcmp(this->staticname,modsyms[j].name))
99 log(DEBUG,"Loading symbol...");
100 v = modsyms[j].value;
105 err = "Module symbol missing from the core";
111 bool DLLManager::GetSymbol(void **v, char *sym_name)
113 // try extract a symbol from the library
114 // get any error message is there is any
118 *v = dlsym( h, sym_name );
119 err = (char*)dlerror();
133 DLLFactoryBase::DLLFactoryBase(char *fname, char *factory) : DLLManager(fname)
135 // try get the factory function if there is no error yet
142 GetSymbol( factory_func, factory ? factory : (char*)"init_module" );
144 GetSymbol( (void **)&factory_func, factory ? factory : (char*)"init_module" );
150 DLLFactoryBase::~DLLFactoryBase()