22 |
|
* $Id$ |
23 |
|
*/ |
24 |
|
|
25 |
+ |
#include "ltdl.h" |
26 |
+ |
|
27 |
|
#include "stdinc.h" |
28 |
|
#include "list.h" |
29 |
|
#include "modules.h" |
42 |
|
|
43 |
|
dlink_list mod_list = { NULL, NULL, 0 }; |
44 |
|
|
45 |
+ |
|
46 |
+ |
static const char *unknown_ver = "<unknown>"; |
47 |
+ |
|
48 |
|
static const char *core_module_table[] = |
49 |
|
{ |
50 |
|
"m_die.la", |
98 |
|
}; |
99 |
|
|
100 |
|
|
101 |
+ |
int |
102 |
+ |
modules_valid_suffix(const char *name) |
103 |
+ |
{ |
104 |
+ |
return ((name = strrchr(name, '.'))) && !strcmp(name, ".la"); |
105 |
+ |
} |
106 |
+ |
|
107 |
+ |
/* unload_one_module() |
108 |
+ |
* |
109 |
+ |
* inputs - name of module to unload |
110 |
+ |
* - 1 to say modules unloaded, 0 to not |
111 |
+ |
* output - 0 if successful, -1 if error |
112 |
+ |
* side effects - module is unloaded |
113 |
+ |
*/ |
114 |
+ |
int |
115 |
+ |
unload_one_module(const char *name, int warn) |
116 |
+ |
{ |
117 |
+ |
struct module *modp = NULL; |
118 |
+ |
|
119 |
+ |
if ((modp = findmodule_byname(name)) == NULL) |
120 |
+ |
return -1; |
121 |
+ |
|
122 |
+ |
if (modp->modexit) |
123 |
+ |
modp->modexit(); |
124 |
+ |
|
125 |
+ |
assert(dlink_list_length(&mod_list) > 0); |
126 |
+ |
dlinkDelete(&modp->node, &mod_list); |
127 |
+ |
MyFree(modp->name); |
128 |
+ |
|
129 |
+ |
lt_dlclose(modp->handle); |
130 |
+ |
|
131 |
+ |
if (warn == 1) |
132 |
+ |
{ |
133 |
+ |
ilog(L_INFO, "Module %s unloaded", name); |
134 |
+ |
sendto_realops_flags(UMODE_ALL, L_ALL, "Module %s unloaded", name); |
135 |
+ |
} |
136 |
+ |
|
137 |
+ |
return 0; |
138 |
+ |
} |
139 |
+ |
|
140 |
+ |
/* load_a_module() |
141 |
+ |
* |
142 |
+ |
* inputs - path name of module, int to notice, int of core |
143 |
+ |
* output - -1 if error 0 if success |
144 |
+ |
* side effects - loads a module if successful |
145 |
+ |
*/ |
146 |
+ |
int |
147 |
+ |
load_a_module(const char *path, int warn, int core) |
148 |
+ |
{ |
149 |
+ |
lt_dlhandle tmpptr = NULL; |
150 |
+ |
const char *mod_basename = NULL; |
151 |
+ |
struct module *modp = NULL; |
152 |
+ |
|
153 |
+ |
if (findmodule_byname((mod_basename = libio_basename(path)))) |
154 |
+ |
return 1; |
155 |
+ |
|
156 |
+ |
if (!(tmpptr = lt_dlopen(path))) { |
157 |
+ |
const char *err = ((err = lt_dlerror())) ? err : "<unknown>"; |
158 |
+ |
|
159 |
+ |
sendto_realops_flags(UMODE_ALL, L_ALL, "Error loading module %s: %s", |
160 |
+ |
mod_basename, err); |
161 |
+ |
ilog(L_WARN, "Error loading module %s: %s", mod_basename, err); |
162 |
+ |
return -1; |
163 |
+ |
} |
164 |
+ |
|
165 |
+ |
if ((modp = lt_dlsym(tmpptr, "module_entry")) == NULL) |
166 |
+ |
{ |
167 |
+ |
sendto_realops_flags(UMODE_ALL, L_ALL, "Module %s has no module_entry export", |
168 |
+ |
mod_basename); |
169 |
+ |
ilog(L_WARN, "Module %s has no module_entry export", mod_basename); |
170 |
+ |
lt_dlclose(tmpptr); |
171 |
+ |
return -1; |
172 |
+ |
} |
173 |
+ |
|
174 |
+ |
modp->handle = tmpptr; |
175 |
+ |
|
176 |
+ |
if (EmptyString(modp->version)) |
177 |
+ |
modp->version = unknown_ver; |
178 |
+ |
|
179 |
+ |
if (core) |
180 |
+ |
modp->flags |= MODULE_FLAG_CORE; |
181 |
+ |
|
182 |
+ |
DupString(modp->name, mod_basename); |
183 |
+ |
dlinkAdd(modp, &modp->node, &mod_list); |
184 |
+ |
|
185 |
+ |
if (modp->modinit) |
186 |
+ |
modp->modinit(); |
187 |
+ |
|
188 |
+ |
if (warn == 1) |
189 |
+ |
{ |
190 |
+ |
sendto_realops_flags(UMODE_ALL, L_ALL, |
191 |
+ |
"Module %s [version: %s handle: %p] loaded.", |
192 |
+ |
modp->name, modp->version, tmpptr); |
193 |
+ |
ilog(L_WARN, "Module %s [version: %s handle: %p] loaded.", |
194 |
+ |
modp->name, modp->version, tmpptr); |
195 |
+ |
} |
196 |
+ |
|
197 |
+ |
return 0; |
198 |
+ |
} |
199 |
+ |
|
200 |
|
/* |
201 |
|
* modules_init |
202 |
|
* |
207 |
|
void |
208 |
|
modules_init(void) |
209 |
|
{ |
210 |
< |
dynlink_init(); |
210 |
> |
if (lt_dlinit()) |
211 |
> |
{ |
212 |
> |
ilog(L_ERROR, "Couldn't initialize the libltdl run time dynamic" |
213 |
> |
" link library. Exiting."); |
214 |
> |
exit(0); |
215 |
> |
} |
216 |
|
|
217 |
|
mod_add_cmd(&modload_msgtab); |
218 |
|
mod_add_cmd(&modunload_msgtab); |
290 |
|
void |
291 |
|
mod_clear_paths(void) |
292 |
|
{ |
293 |
< |
struct module_path *pathst; |
294 |
< |
dlink_node *ptr; |
186 |
< |
dlink_node *next_ptr; |
293 |
> |
struct module_path *pathst = NULL; |
294 |
> |
dlink_node *ptr = NULL, *next_ptr = NULL; |
295 |
|
|
296 |
|
DLINK_FOREACH_SAFE(ptr, next_ptr, mod_paths.head) |
297 |
|
{ |