author | Tero Marttila <terom@fixme.fi> |
Wed, 01 Apr 2009 18:30:47 +0300 | |
changeset 108 | 50ff7ac8a725 |
parent 103 | 454aea1e4f11 |
child 110 | 43e9a7984955 |
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 |
|
103
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
41 |
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
|
42 |
{ |
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
43 |
return module->info.name; |
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
44 |
} |
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
45 |
|
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
|
46 |
/** |
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
47 |
* 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
|
48 |
*/ |
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
|
49 |
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
|
50 |
{ |
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
|
51 |
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
|
52 |
|
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
|
53 |
// 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
|
54 |
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
|
55 |
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
|
56 |
|
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
|
57 |
// 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
|
58 |
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
|
59 |
|
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
|
60 |
// load |
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
61 |
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
|
62 |
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
|
63 |
|
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
|
64 |
// 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
|
65 |
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
|
66 |
} |
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
|
67 |
|
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
68 |
/** |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
69 |
* 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
|
70 |
*/ |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
71 |
char *strfmt (const char *fmt, ...) |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
72 |
{ |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
73 |
va_list vargs; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
74 |
size_t len; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
75 |
char *buf; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
76 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
77 |
// 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
|
78 |
va_start(vargs, fmt); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
79 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
80 |
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
|
81 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
82 |
va_end(vargs); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
83 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
84 |
// malloc |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
85 |
if ((buf = malloc(len)) == NULL) |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
86 |
return NULL; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
87 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
88 |
// format |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
89 |
va_start(vargs, fmt); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
90 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
91 |
vsnprintf(buf, len, fmt, vargs); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
92 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
93 |
va_end(vargs); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
94 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
95 |
// ok |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
96 |
return buf; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
97 |
} |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
98 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
99 |
/** |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
100 |
* 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
|
101 |
*/ |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
102 |
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
|
103 |
{ |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
104 |
char *path = NULL; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
105 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
106 |
// build the path... |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
107 |
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
|
108 |
JUMP_SET_ERROR(err, ERR_STRDUP); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
109 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
110 |
// exists and readable? |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
111 |
if (access(path, R_OK)) |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
112 |
// 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
|
113 |
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
|
114 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
115 |
// ok |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
116 |
return path; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
117 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
118 |
error: |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
119 |
// release the dynamically allocated path |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
120 |
free(path); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
121 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
122 |
return NULL; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
123 |
} |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
124 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
125 |
err_t module_load (struct modules *modules, struct module **module_ptr, const struct module_info *_info, struct error_info *err) |
54 | 126 |
{ |
127 |
struct module *module; |
|
128 |
||
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
|
129 |
// validate the module name |
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
130 |
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
|
131 |
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
|
132 |
|
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
133 |
// already open with the same name? |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
134 |
if (module_get(modules, _info->name)) |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
135 |
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
|
136 |
|
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
|
137 |
// 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
|
138 |
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
|
139 |
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
|
140 |
|
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
|
141 |
// store |
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
142 |
module->info = *_info; |
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
143 |
module->modules = modules; |
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
144 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
145 |
// add to modules list |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
146 |
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
|
147 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
148 |
// lookup path? |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
149 |
if (!module->info.path) { |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
150 |
// have a search path? |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
151 |
if (!modules->path) |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
152 |
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
|
153 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
154 |
// try and resolve the path automatically |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
155 |
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
|
156 |
goto error; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
157 |
|
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
158 |
// use that path |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
159 |
module->info.path = module->path_buf; |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
160 |
} |
54 | 161 |
|
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
|
162 |
// 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
|
163 |
(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
|
164 |
|
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
|
165 |
// load it |
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
166 |
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
|
167 |
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
|
168 |
|
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
169 |
// 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
|
170 |
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
|
171 |
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
|
172 |
|
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
173 |
// 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
|
174 |
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
|
175 |
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
|
176 |
|
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
|
177 |
// ok |
65
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
57
diff
changeset
|
178 |
if (module_ptr) |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
57
diff
changeset
|
179 |
*module_ptr = 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
|
180 |
|
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
|
181 |
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
|
182 |
|
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
|
183 |
error: |
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
184 |
// cleanup |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
185 |
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
|
186 |
|
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
|
187 |
return ERROR_CODE(err); |
54 | 188 |
} |
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
|
189 |
|
66
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
190 |
struct module* module_get (struct modules *modules, const char *name) |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
191 |
{ |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
192 |
struct module *module = NULL; |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
193 |
|
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
194 |
// look for it... |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
195 |
TAILQ_FOREACH(module, &modules->list, modules_list) { |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
196 |
if (strcasecmp(module->info.name, name) == 0) |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
197 |
// found it |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
198 |
return module; |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
199 |
} |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
200 |
|
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
201 |
// no such module |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
202 |
return NULL; |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
203 |
} |
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
204 |
|
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
|
205 |
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
|
206 |
{ |
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
|
207 |
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
|
208 |
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
|
209 |
|
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
|
210 |
// 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
|
211 |
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
|
212 |
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
|
213 |
|
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
|
214 |
// 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
|
215 |
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
|
216 |
} |
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
|
217 |
|
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
|
218 |
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
|
219 |
{ |
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
|
220 |
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
|
221 |
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
|
222 |
|
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
|
223 |
// 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
|
224 |
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
|
225 |
|
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
|
226 |
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
|
227 |
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
|
228 |
} |
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
|
229 |
|
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
|
230 |
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
|
231 |
{ |
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
|
232 |
// 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
|
233 |
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
|
234 |
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
|
235 |
|
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
|
236 |
// 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
|
237 |
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
|
238 |
} |
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
239 |
|
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
240 |
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
|
241 |
{ |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
242 |
err_t err; |
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
|
243 |
|
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
244 |
// invoke the unload 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
|
245 |
if ((err = module->desc->unload(module->ctx))) |
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
246 |
return err; |
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
|
247 |
|
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
|
248 |
// update status |
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
|
249 |
// XXX: before or after? |
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
|
250 |
module->unloading = true; |
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
251 |
|
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
252 |
// ok |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
253 |
return SUCCESS; |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
254 |
} |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
255 |
|
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
256 |
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
|
257 |
{ |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
258 |
// remove from modules list |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
259 |
TAILQ_REMOVE(&module->modules->list, module, modules_list); |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
260 |
|
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
261 |
// unload the dl handle |
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
262 |
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
|
263 |
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
|
264 |
|
108
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
265 |
// release the path buf, if any |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
266 |
free(module->path_buf); |
50ff7ac8a725
implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents:
103
diff
changeset
|
267 |
|
70
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
268 |
// free the module info |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
269 |
free(module); |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
270 |
} |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
271 |
|
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
272 |
err_t modules_unload (struct modules *modules) |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
273 |
{ |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
274 |
struct module *module; |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
275 |
err_t err; |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
276 |
|
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
277 |
// unload each module in turn |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
278 |
TAILQ_FOREACH(module, &modules->list, modules_list) { |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
279 |
if ((err = module_unload(module))) |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
280 |
log_warn("module_unload(%s) failed: %s", module->info.name, error_name(err)); |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
281 |
} |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
282 |
|
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
283 |
// ok |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
284 |
return SUCCESS; |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
285 |
} |
a9a4c5e6aa30
implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
286 |
|
103
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
287 |
void modules_destroy (struct modules *modules) |
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
288 |
{ |
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
289 |
struct module *module; |
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
290 |
|
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
291 |
// destroy each module |
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
292 |
while ((module = TAILQ_FIRST(&modules->list))) |
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
293 |
module_destroy(module); |
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
294 |
|
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
295 |
// ourselves |
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
296 |
free(modules); |
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
297 |
} |
454aea1e4f11
implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents:
100
diff
changeset
|
298 |