author | Tero Marttila <terom@fixme.fi> |
Mon, 04 May 2009 20:55:04 +0300 | |
branch | new-transport |
changeset 168 | a58ad50911fc |
parent 138 | a716c621cb90 |
child 180 | 22967b165692 |
permissions | -rw-r--r-- |
54 | 1 |
#include "module.h" |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
2 |
#include "log.h" |
54 | 3 |
|
4 |
#include <stdlib.h> |
|
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
5 |
#include <unistd.h> |
54 | 6 |
#include <dlfcn.h> |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
7 |
#include <string.h> |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
8 |
#include <assert.h> |
54 | 9 |
|
10 |
err_t modules_create (struct modules **modules_ptr, struct nexus *nexus) |
|
11 |
{ |
|
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
12 |
struct modules *modules; |
54 | 13 |
|
14 |
// alloc |
|
15 |
if ((modules = calloc(1, sizeof(*modules))) == NULL) |
|
16 |
return ERR_CALLOC; |
|
17 |
||
18 |
// init |
|
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
19 |
TAILQ_INIT(&modules->list); |
54 | 20 |
|
21 |
// store |
|
22 |
modules->nexus = nexus; |
|
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
23 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
24 |
// ok |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
25 |
*modules_ptr = modules; |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
26 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
27 |
return SUCCESS; |
54 | 28 |
} |
29 |
||
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
30 |
const char* modules_path (struct modules *modules, const char *path) |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
31 |
{ |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
32 |
const char *old_path = modules->path; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
33 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
34 |
if (path) |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
35 |
// replace |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
36 |
modules->path = path; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
37 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
38 |
return old_path; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
39 |
} |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
40 |
|
110
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
41 |
/** |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
42 |
* module_get without the refcount stuff |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
43 |
*/ |
134
978041c1c04d
update TODO, partially update error.c, rename module_get to modules_get, update config.lua
Tero Marttila <terom@fixme.fi>
parents:
119
diff
changeset
|
44 |
static struct module* modules_lookup (struct modules *modules, const char *name) |
110
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
45 |
{ |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
46 |
struct module *module = NULL; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
47 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
48 |
// look for it... |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
49 |
TAILQ_FOREACH(module, &modules->list, modules_list) { |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
50 |
if (strcasecmp(module->info.name, name) == 0) { |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
51 |
// found it |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
52 |
return module; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
53 |
} |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
54 |
} |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
55 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
56 |
// no such module |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
57 |
return NULL; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
58 |
} |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
59 |
|
134
978041c1c04d
update TODO, partially update error.c, rename module_get to modules_get, update config.lua
Tero Marttila <terom@fixme.fi>
parents:
119
diff
changeset
|
60 |
struct module* modules_get (struct modules *modules, const char *name) |
110
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
61 |
{ |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
62 |
struct module *module; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
63 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
64 |
// get it |
134
978041c1c04d
update TODO, partially update error.c, rename module_get to modules_get, update config.lua
Tero Marttila <terom@fixme.fi>
parents:
119
diff
changeset
|
65 |
if (!(module = modules_lookup(modules, name))) |
110
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
66 |
return NULL; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
67 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
68 |
// up the refcount |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
69 |
module->refcount++; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
70 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
71 |
// ok |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
72 |
return module; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
73 |
} |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
74 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
75 |
err_t modules_unload (struct modules *modules) |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
76 |
{ |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
77 |
struct module *module; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
78 |
err_t err; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
79 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
80 |
// unload each module in turn |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
81 |
while ((module = TAILQ_FIRST(&modules->list))) { |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
82 |
if ((err = module_unload(module))) |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
83 |
log_warn("module_unload(%s) failed: %s", module->info.name, error_name(err)); |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
84 |
} |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
85 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
86 |
// ok |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
87 |
return SUCCESS; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
88 |
} |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
89 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
90 |
void modules_destroy (struct modules *modules) |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
91 |
{ |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
92 |
struct module *module; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
93 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
94 |
// destroy each module |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
95 |
while ((module = TAILQ_FIRST(&modules->list))) |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
96 |
module_destroy(module); |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
97 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
98 |
// ourselves |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
99 |
free(modules); |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
100 |
} |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
101 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
102 |
|
103
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
103 |
const char* module_name (struct module *module) |
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
104 |
{ |
138
a716c621cb90
implement blackhole filters for logwatch, and stop applying filters after the first hit
Tero Marttila <terom@fixme.fi>
parents:
134
diff
changeset
|
105 |
return module ? module->info.name : NULL; |
103
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
106 |
} |
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
107 |
|
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
108 |
/** |
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
109 |
* Load the symbol named "<module>_<suffix>". |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
110 |
*/ |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
111 |
static err_t module_symbol (struct module *module, void **sym, const char *suffix) |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
112 |
{ |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
113 |
char sym_name[MODULE_SYMBOL_MAX]; |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
114 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
115 |
// validate the length of the suffix |
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
116 |
assert(strlen(module->info.name) <= MODULE_NAME_MAX); |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
117 |
assert(strlen(suffix) <= MODULE_SUFFIX_MAX); |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
118 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
119 |
// format |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
120 |
sprintf(sym_name, "%s_%s", module->info.name, suffix); |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
121 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
122 |
// load |
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
123 |
if ((*sym = dlsym(module->handle, sym_name)) == NULL) |
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
124 |
return ERR_MODULE_SYM; |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
125 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
126 |
// ok |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
127 |
return SUCCESS; |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
128 |
} |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
129 |
|
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
130 |
/** |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
131 |
* XXX: ugly function to format to a dynamically allocated string |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
132 |
*/ |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
133 |
char *strfmt (const char *fmt, ...) |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
134 |
{ |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
135 |
va_list vargs; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
136 |
size_t len; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
137 |
char *buf; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
138 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
139 |
// figure out the length of the resulting string |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
140 |
va_start(vargs, fmt); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
141 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
142 |
len = vsnprintf(NULL, 0, fmt, vargs) + 1; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
143 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
144 |
va_end(vargs); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
145 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
146 |
// malloc |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
147 |
if ((buf = malloc(len)) == NULL) |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
148 |
return NULL; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
149 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
150 |
// format |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
151 |
va_start(vargs, fmt); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
152 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
153 |
vsnprintf(buf, len, fmt, vargs); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
154 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
155 |
va_end(vargs); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
156 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
157 |
// ok |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
158 |
return buf; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
159 |
} |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
160 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
161 |
/** |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
162 |
* Looks up a module's path by name, returning a dynamically allocated string with the path on success |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
163 |
*/ |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
164 |
static char* module_find (struct modules *modules, struct module_info *info, struct error_info *err) |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
165 |
{ |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
166 |
char *path = NULL; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
167 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
168 |
// build the path... |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
169 |
if ((path = strfmt("%s/mod_%s.so", modules->path, info->name)) == NULL) |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
170 |
JUMP_SET_ERROR(err, ERR_STRDUP); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
171 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
172 |
// exists and readable? |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
173 |
if (access(path, R_OK)) |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
174 |
// XXX: this doesn't contain the path... |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
175 |
JUMP_SET_ERROR_STR(err, ERR_MODULE_PATH, "module not found in search path"); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
176 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
177 |
// ok |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
178 |
return path; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
179 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
180 |
error: |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
181 |
// release the dynamically allocated path |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
182 |
free(path); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
183 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
184 |
return NULL; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
185 |
} |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
186 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
187 |
err_t module_load (struct modules *modules, struct module **module_ptr, const struct module_info *_info, struct error_info *err) |
54 | 188 |
{ |
189 |
struct module *module; |
|
190 |
||
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
191 |
// validate the module name |
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
192 |
if (strlen(_info->name) > MODULE_NAME_MAX) |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
193 |
return SET_ERROR(err, ERR_MODULE_NAME); |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
194 |
|
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
195 |
// already open with the same name? |
134
978041c1c04d
update TODO, partially update error.c, rename module_get to modules_get, update config.lua
Tero Marttila <terom@fixme.fi>
parents:
119
diff
changeset
|
196 |
if (modules_lookup(modules, _info->name)) |
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
197 |
return SET_ERROR(err, ERR_MODULE_DUP); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
198 |
|
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
199 |
// alloc |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
200 |
if ((module = calloc(1, sizeof(*module))) == NULL) |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
201 |
return SET_ERROR(err, ERR_CALLOC); |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
202 |
|
110
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
203 |
// initialize |
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
204 |
module->info = *_info; |
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
205 |
module->modules = modules; |
110
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
206 |
module->refcount = 1; |
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
207 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
208 |
// add to modules list |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
209 |
TAILQ_INSERT_TAIL(&modules->list, module, modules_list); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
210 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
211 |
// lookup path? |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
212 |
if (!module->info.path) { |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
213 |
// have a search path? |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
214 |
if (!modules->path) |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
215 |
JUMP_SET_ERROR_STR(err, ERR_MODULE_PATH, "no module search path defined"); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
216 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
217 |
// try and resolve the path automatically |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
218 |
if ((module->path_buf = module_find(modules, &module->info, err)) == NULL) |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
219 |
goto error; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
220 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
221 |
// use that path |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
222 |
module->info.path = module->path_buf; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
223 |
} |
54 | 224 |
|
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
225 |
// clear dlerrors |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
226 |
(void) dlerror(); |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
227 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
228 |
// load it |
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
229 |
if ((module->handle = dlopen(module->info.path, RTLD_NOW)) == NULL) |
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
230 |
JUMP_SET_ERROR_STR(err, ERR_MODULE_OPEN, dlerror()); |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
231 |
|
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
232 |
// load the funcs symbol |
100
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
233 |
if ((ERROR_CODE(err) = module_symbol(module, (void **) &module->desc, "module"))) |
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
234 |
JUMP_SET_ERROR_STR(err, ERROR_CODE(err), dlerror()); |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
235 |
|
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
236 |
// call the init func |
100
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
237 |
if ((module->desc->init(modules->nexus, &module->ctx, err))) |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
238 |
goto error; |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
239 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
240 |
// ok |
111
5a1ebffca81a
fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents:
110
diff
changeset
|
241 |
if (module_ptr) { |
5a1ebffca81a
fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents:
110
diff
changeset
|
242 |
module->refcount++; |
65
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
57
diff
changeset
|
243 |
*module_ptr = module; |
111
5a1ebffca81a
fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents:
110
diff
changeset
|
244 |
} |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
245 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
246 |
return SUCCESS; |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
247 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
248 |
error: |
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
249 |
// cleanup |
110
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
250 |
module->refcount = 0; |
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
251 |
module_destroy(module); |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
252 |
|
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
253 |
return ERROR_CODE(err); |
54 | 254 |
} |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
255 |
|
110
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
256 |
void module_put (struct module *module) |
66
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
257 |
{ |
110
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
258 |
assert(module->refcount > 0); |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
259 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
260 |
// decrement, just return if still alive |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
261 |
if (--module->refcount > 0) |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
262 |
return; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
263 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
264 |
// refcount zero, destroy |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
265 |
module_destroy(module); |
66
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
266 |
} |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
267 |
|
100
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
268 |
err_t module_conf_raw (struct module *module, const char *name, char *value, struct error_info *err) |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
269 |
{ |
110
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
270 |
// sanity-check |
100
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
271 |
if (!module->desc->config_options) |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
272 |
RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "module does not have any config options"); |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
273 |
|
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
274 |
// wrong state |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
275 |
if (module->unloading) |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
276 |
RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "module is being unloaded"); |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
277 |
|
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
278 |
// parse/apply using the module's stuff |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
279 |
return config_apply_raw(module->desc->config_options, module->modules->nexus, module->ctx, name, value, err); |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
280 |
} |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
281 |
|
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
282 |
const struct config_option* module_conf_lookup (struct module *module, const char *name, struct error_info *err) |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
283 |
{ |
110
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
284 |
// sanity-check |
100
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
285 |
if (!module->desc->config_options) |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
286 |
JUMP_SET_ERROR_STR(err, ERR_MODULE_CONF, "module does not have any config options"); |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
287 |
|
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
288 |
// direct lookup |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
289 |
return config_lookup(module->desc->config_options, name, err); |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
290 |
|
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
291 |
error: |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
292 |
return NULL; |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
293 |
} |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
294 |
|
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
295 |
err_t module_conf (struct module *module, const struct config_option *opt, const struct config_value *value, struct error_info *err) |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
296 |
{ |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
297 |
// wrong state |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
298 |
if (module->unloading) |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
299 |
RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "module is being unloaded"); |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
300 |
|
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
301 |
// apply with the module's ctx |
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
302 |
return config_apply_opt(opt, module->ctx, value, err); |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
303 |
} |
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
304 |
|
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
305 |
err_t module_unload (struct module *module) |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
306 |
{ |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
307 |
err_t err; |
110
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
308 |
|
111
5a1ebffca81a
fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents:
110
diff
changeset
|
309 |
// wrong state |
5a1ebffca81a
fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents:
110
diff
changeset
|
310 |
if (module->unloading) |
5a1ebffca81a
fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents:
110
diff
changeset
|
311 |
return ERR_MODULE_STATE; |
100
cfb7776bd6f0
improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents:
70
diff
changeset
|
312 |
|
110
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
313 |
// remove from modules list |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
314 |
TAILQ_REMOVE(&module->modules->list, module, modules_list); |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
315 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
316 |
// update status |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
317 |
module->unloading = true; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
318 |
|
119
64f50072db9e
add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
111
diff
changeset
|
319 |
if (module->desc->unload) { |
64f50072db9e
add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
111
diff
changeset
|
320 |
// invoke the unload func, passing it our reference |
64f50072db9e
add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
111
diff
changeset
|
321 |
// note that the module might not exist anymore after calling this |
64f50072db9e
add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
111
diff
changeset
|
322 |
if ((err = module->desc->unload(module->ctx, module))) { |
64f50072db9e
add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
111
diff
changeset
|
323 |
// mark it as "unloaded" |
64f50072db9e
add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
111
diff
changeset
|
324 |
module_unloaded(module); |
64f50072db9e
add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
111
diff
changeset
|
325 |
|
64f50072db9e
add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
111
diff
changeset
|
326 |
return err; |
64f50072db9e
add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
111
diff
changeset
|
327 |
} |
64f50072db9e
add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
111
diff
changeset
|
328 |
|
64f50072db9e
add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
111
diff
changeset
|
329 |
} else { |
64f50072db9e
add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
111
diff
changeset
|
330 |
// no unload procedure, just destroy it as soon as needed |
111
5a1ebffca81a
fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents:
110
diff
changeset
|
331 |
module_unloaded(module); |
5a1ebffca81a
fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents:
110
diff
changeset
|
332 |
|
5a1ebffca81a
fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents:
110
diff
changeset
|
333 |
} |
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
334 |
// ok |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
335 |
return SUCCESS; |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
336 |
} |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
337 |
|
110
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
338 |
/** |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
339 |
* A wrapper for module_destroy suitable for use as a libevent callback |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
340 |
*/ |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
341 |
static void _module_destroy (int fd, short what, void *arg) |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
342 |
{ |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
343 |
struct module *module = arg; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
344 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
345 |
(void) fd; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
346 |
(void) what; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
347 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
348 |
// execute |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
349 |
module_destroy(module); |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
350 |
} |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
351 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
352 |
void module_unloaded (struct module *module) |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
353 |
{ |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
354 |
struct timeval tv = { 0, 0 }; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
355 |
assert(module->refcount > 0); |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
356 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
357 |
// decrement, just return if still alive |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
358 |
if (--module->refcount > 0) |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
359 |
return; |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
360 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
361 |
// schedule a deferred module_destroy |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
362 |
if (event_base_once(module->modules->nexus->ev_base, -1, EV_TIMEOUT, &_module_destroy, module, &tv)) |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
363 |
// XXX: how to reach? |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
364 |
log_fatal("event_base_once failed, unable to schedule deferred module_destroy"); |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
365 |
} |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
366 |
|
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
367 |
void module_destroy (struct module *module) |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
368 |
{ |
110
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
369 |
// XXX: warn about destroy with significant refcount... |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
370 |
if (module->refcount) |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
371 |
log_warn("destroying module %s with refcount>0: %zu", module_name(module), module->refcount); |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
372 |
else |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
373 |
log_debug("destroying module %s", module_name(module)); |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
374 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
375 |
// still need to remove from modules_list? |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
376 |
if (!module->unloading) |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
377 |
TAILQ_REMOVE(&module->modules->list, module, modules_list); |
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
378 |
|
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
379 |
// run the destroy hook |
119
64f50072db9e
add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
111
diff
changeset
|
380 |
if (module->desc && module->desc->destroy && module->ctx) |
110
43e9a7984955
fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents:
108
diff
changeset
|
381 |
module->desc->destroy(module->ctx); |
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
382 |
|
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
383 |
// unload the dl handle |
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
384 |
if (module->handle && dlclose(module->handle)) |
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
385 |
log_error("dlclose(%s): %s", module->info.name, dlerror()); |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
386 |
|
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
387 |
// release the path buf, if any |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
388 |
free(module->path_buf); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
389 |
|
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
390 |
// free the module info |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
391 |
free(module); |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
392 |
} |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
393 |
|
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
394 |