27 |
|
#include "stdinc.h" |
28 |
|
#include "list.h" |
29 |
|
#include "modules.h" |
30 |
< |
#include "s_log.h" |
30 |
> |
#include "log.h" |
31 |
|
#include "ircd.h" |
32 |
|
#include "client.h" |
33 |
|
#include "send.h" |
34 |
< |
#include "s_conf.h" |
35 |
< |
#include "handlers.h" |
34 |
> |
#include "conf.h" |
35 |
|
#include "numeric.h" |
36 |
|
#include "parse.h" |
37 |
|
#include "ircd_defs.h" |
39 |
|
#include "memory.h" |
40 |
|
|
41 |
|
|
42 |
< |
dlink_list mod_list = { NULL, NULL, 0 }; |
44 |
< |
|
42 |
> |
static dlink_list modules_list = { NULL, NULL, 0 }; |
43 |
|
|
44 |
|
static const char *unknown_ver = "<unknown>"; |
45 |
|
|
120 |
|
if (modp->modexit) |
121 |
|
modp->modexit(); |
122 |
|
|
123 |
< |
assert(dlink_list_length(&mod_list) > 0); |
124 |
< |
dlinkDelete(&modp->node, &mod_list); |
123 |
> |
assert(dlink_list_length(&modules_list) > 0); |
124 |
> |
dlinkDelete(&modp->node, &modules_list); |
125 |
|
MyFree(modp->name); |
126 |
|
|
127 |
|
lt_dlclose(modp->handle); |
128 |
|
|
129 |
|
if (warn == 1) |
130 |
|
{ |
131 |
< |
ilog(L_INFO, "Module %s unloaded", name); |
131 |
> |
ilog(LOG_TYPE_IRCD, "Module %s unloaded", name); |
132 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, "Module %s unloaded", name); |
133 |
|
} |
134 |
|
|
142 |
|
* side effects - loads a module if successful |
143 |
|
*/ |
144 |
|
int |
145 |
< |
load_a_module(const char *path, int warn, int core) |
145 |
> |
load_a_module(const char *path, int warn) |
146 |
|
{ |
147 |
|
lt_dlhandle tmpptr = NULL; |
148 |
|
const char *mod_basename = NULL; |
156 |
|
|
157 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, "Error loading module %s: %s", |
158 |
|
mod_basename, err); |
159 |
< |
ilog(L_WARN, "Error loading module %s: %s", mod_basename, err); |
159 |
> |
ilog(LOG_TYPE_IRCD, "Error loading module %s: %s", mod_basename, err); |
160 |
|
return -1; |
161 |
|
} |
162 |
|
|
164 |
|
{ |
165 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, "Module %s has no module_entry export", |
166 |
|
mod_basename); |
167 |
< |
ilog(L_WARN, "Module %s has no module_entry export", mod_basename); |
167 |
> |
ilog(LOG_TYPE_IRCD, "Module %s has no module_entry export", mod_basename); |
168 |
|
lt_dlclose(tmpptr); |
169 |
|
return -1; |
170 |
|
} |
174 |
|
if (EmptyString(modp->version)) |
175 |
|
modp->version = unknown_ver; |
176 |
|
|
179 |
– |
if (core) |
180 |
– |
modp->flags |= MODULE_FLAG_CORE; |
181 |
– |
|
177 |
|
DupString(modp->name, mod_basename); |
178 |
< |
dlinkAdd(modp, &modp->node, &mod_list); |
178 |
> |
dlinkAdd(modp, &modp->node, &modules_list); |
179 |
|
|
180 |
|
if (modp->modinit) |
181 |
|
modp->modinit(); |
185 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
186 |
|
"Module %s [version: %s handle: %p] loaded.", |
187 |
|
modp->name, modp->version, tmpptr); |
188 |
< |
ilog(L_WARN, "Module %s [version: %s handle: %p] loaded.", |
188 |
> |
ilog(LOG_TYPE_IRCD, "Module %s [version: %s handle: %p] loaded.", |
189 |
|
modp->name, modp->version, tmpptr); |
190 |
|
} |
191 |
|
|
204 |
|
{ |
205 |
|
if (lt_dlinit()) |
206 |
|
{ |
207 |
< |
ilog(L_ERROR, "Couldn't initialize the libltdl run time dynamic" |
207 |
> |
ilog(LOG_TYPE_IRCD, "Couldn't initialize the libltdl run time dynamic" |
208 |
|
" link library. Exiting."); |
209 |
|
exit(0); |
210 |
|
} |
226 |
|
mod_find_path(const char *path) |
227 |
|
{ |
228 |
|
dlink_node *ptr; |
234 |
– |
struct module_path *mpath; |
229 |
|
|
230 |
|
DLINK_FOREACH(ptr, mod_paths.head) |
231 |
|
{ |
232 |
< |
mpath = ptr->data; |
232 |
> |
struct module_path *mpath = ptr->data; |
233 |
|
|
234 |
|
if (!strcmp(path, mpath->path)) |
235 |
|
return mpath; |
284 |
|
void |
285 |
|
mod_clear_paths(void) |
286 |
|
{ |
293 |
– |
struct module_path *pathst = NULL; |
287 |
|
dlink_node *ptr = NULL, *next_ptr = NULL; |
288 |
|
|
289 |
|
DLINK_FOREACH_SAFE(ptr, next_ptr, mod_paths.head) |
290 |
|
{ |
291 |
< |
pathst = ptr->data; |
292 |
< |
|
300 |
< |
dlinkDelete(&pathst->node, &mod_paths); |
301 |
< |
MyFree(pathst); |
291 |
> |
dlinkDelete(ptr, &mod_paths); |
292 |
> |
MyFree(ptr->data); |
293 |
|
} |
294 |
|
|
295 |
|
DLINK_FOREACH_SAFE(ptr, next_ptr, conf_modules.head) |
296 |
|
{ |
297 |
< |
pathst = ptr->data; |
298 |
< |
|
308 |
< |
dlinkDelete(&pathst->node, &conf_modules); |
309 |
< |
MyFree(pathst); |
297 |
> |
dlinkDelete(ptr, &conf_modules); |
298 |
> |
MyFree(ptr->data); |
299 |
|
} |
300 |
|
} |
301 |
|
|
310 |
|
{ |
311 |
|
dlink_node *ptr = NULL; |
312 |
|
|
313 |
< |
DLINK_FOREACH(ptr, mod_list.head) |
313 |
> |
DLINK_FOREACH(ptr, modules_list.head) |
314 |
|
{ |
315 |
|
struct module *modp = ptr->data; |
316 |
|
|
334 |
|
struct dirent *ldirent = NULL; |
335 |
|
char module_fq_name[PATH_MAX + 1]; |
336 |
|
|
348 |
– |
modules_init(); |
349 |
– |
|
337 |
|
if ((system_module_dir = opendir(AUTOMODPATH)) == NULL) |
338 |
|
{ |
339 |
< |
ilog(L_WARN, "Could not load modules from %s: %s", |
339 |
> |
ilog(LOG_TYPE_IRCD, "Could not load modules from %s: %s", |
340 |
|
AUTOMODPATH, strerror(errno)); |
341 |
|
return; |
342 |
|
} |
347 |
|
{ |
348 |
|
snprintf(module_fq_name, sizeof(module_fq_name), "%s/%s", |
349 |
|
AUTOMODPATH, ldirent->d_name); |
350 |
< |
load_a_module(module_fq_name, warn, 0); |
350 |
> |
load_a_module(module_fq_name, warn); |
351 |
|
} |
352 |
|
} |
353 |
|
|
364 |
|
load_conf_modules(void) |
365 |
|
{ |
366 |
|
dlink_node *ptr = NULL; |
380 |
– |
struct module_path *mpath = NULL; |
367 |
|
|
368 |
|
DLINK_FOREACH(ptr, conf_modules.head) |
369 |
|
{ |
370 |
< |
mpath = ptr->data; |
370 |
> |
struct module_path *mpath = ptr->data; |
371 |
|
|
372 |
|
if (findmodule_byname(mpath->path) == NULL) |
373 |
< |
load_one_module(mpath->path, 0); |
373 |
> |
load_one_module(mpath->path); |
374 |
|
} |
375 |
|
} |
376 |
|
|
391 |
|
snprintf(module_name, sizeof(module_name), "%s%s", |
392 |
|
MODPATH, core_module_table[i]); |
393 |
|
|
394 |
< |
if (load_a_module(module_name, warn, 1) == -1) |
394 |
> |
if (load_a_module(module_name, warn) == -1) |
395 |
|
{ |
396 |
< |
ilog(L_CRIT, "Error loading core module %s: terminating ircd", |
396 |
> |
ilog(LOG_TYPE_IRCD, "Error loading core module %s: terminating ircd", |
397 |
|
core_module_table[i]); |
398 |
|
exit(EXIT_FAILURE); |
399 |
|
} |
408 |
|
* side effects - module is loaded if found. |
409 |
|
*/ |
410 |
|
int |
411 |
< |
load_one_module(const char *path, int coremodule) |
411 |
> |
load_one_module(const char *path) |
412 |
|
{ |
413 |
|
dlink_node *ptr = NULL; |
414 |
|
char modpath[PATH_MAX + 1]; |
425 |
|
|
426 |
|
if (strstr(modpath, "../") == NULL && |
427 |
|
strstr(modpath, "/..") == NULL) |
442 |
– |
{ |
428 |
|
if (!stat(modpath, &statbuf)) |
429 |
< |
{ |
430 |
< |
if (S_ISREG(statbuf.st_mode)) |
446 |
< |
{ |
447 |
< |
/* Regular files only please */ |
448 |
< |
return load_a_module(modpath, 1, coremodule); |
449 |
< |
} |
450 |
< |
} |
451 |
< |
} |
429 |
> |
if (S_ISREG(statbuf.st_mode)) /* Regular files only please */ |
430 |
> |
return load_a_module(modpath, 1); |
431 |
|
} |
432 |
|
|
433 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
434 |
|
"Cannot locate module %s", path); |
435 |
< |
ilog(L_WARN, "Cannot locate module %s", path); |
435 |
> |
ilog(LOG_TYPE_IRCD, "Cannot locate module %s", path); |
436 |
|
return -1; |
437 |
|
} |
438 |
|
|
459 |
|
return; |
460 |
|
} |
461 |
|
|
462 |
< |
load_one_module(parv[1], 0); |
462 |
> |
load_one_module(parv[1]); |
463 |
|
} |
464 |
|
|
465 |
|
/* unload a module .. */ |
535 |
|
return; |
536 |
|
} |
537 |
|
|
538 |
< |
if ((load_one_module(parv[1], check_core) == -1) && check_core) |
538 |
> |
if ((load_one_module(parv[1]) == -1) && check_core) |
539 |
|
{ |
540 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, "Error reloading core " |
541 |
|
"module: %s: terminating ircd", parv[1]); |
542 |
< |
ilog(L_CRIT, "Error loading core module %s: terminating ircd", parv[1]); |
542 |
> |
ilog(LOG_TYPE_IRCD, "Error loading core module %s: terminating ircd", parv[1]); |
543 |
|
exit(0); |
544 |
|
} |
545 |
|
} |
558 |
|
return; |
559 |
|
} |
560 |
|
|
561 |
< |
DLINK_FOREACH(ptr, mod_list.head) |
561 |
> |
DLINK_FOREACH(ptr, modules_list.head) |
562 |
|
{ |
563 |
|
const struct module *modp = ptr->data; |
564 |
|
|
592 |
|
sendto_one(source_p, ":%s NOTICE %s :Reloading all modules", |
593 |
|
me.name, source_p->name); |
594 |
|
|
595 |
< |
modnum = dlink_list_length(&mod_list); |
595 |
> |
modnum = dlink_list_length(&modules_list); |
596 |
|
|
597 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, mod_list.head) |
597 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, modules_list.head) |
598 |
|
{ |
599 |
|
struct module *modp = ptr->data; |
600 |
|
unload_one_module(modp->name, 0); |
605 |
|
load_core_modules(0); |
606 |
|
|
607 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
608 |
< |
"Module Restart: %u modules unloaded, %u modules loaded", |
609 |
< |
modnum, dlink_list_length(&mod_list)); |
610 |
< |
ilog(L_WARN, "Module Restart: %u modules unloaded, %u modules loaded", |
611 |
< |
modnum, dlink_list_length(&mod_list)); |
608 |
> |
"Module Restart: %u modules unloaded, %u modules loaded", |
609 |
> |
modnum, dlink_list_length(&modules_list)); |
610 |
> |
ilog(LOG_TYPE_IRCD, "Module Restart: %u modules unloaded, %u modules loaded", |
611 |
> |
modnum, dlink_list_length(&modules_list)); |
612 |
|
} |