-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.c
40 lines (30 loc) · 1022 Bytes
/
module.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "error.h"
#include "module.h"
#include "module_list.h"
module_config_t sys_mon_load_module(const char* module_config_line) {
char module_name[32];
if (sscanf(module_config_line, "%31s", module_name) != 1)
exit_with_error("invalid config line: %s", module_config_line);
char module_init_name[50] = "module_init_";
strcat(module_init_name, module_name);
module_init init;
for (int i = 0;; i++) {
if (MODULES[i].name == 0)
exit_with_error("can't load module %s", module_name);
if (!strcmp(module_name, MODULES[i].name)) {
init = MODULES[i].init;
break;
}
}
return init(module_config_line + strlen(module_name));
}
int sys_mon_module_write_data(module_config_t * module, writter_t *wt) {
return module->write_data(module->data, wt);
}
void sys_mon_unload_module(module_config_t * module) {
module->unload(module->data);
}