diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2011-01-26 22:47:10 +0300 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2011-01-26 22:47:10 +0300 |
commit | 419de8f6910e4fd5d442068ad5ae41b530169470 (patch) | |
tree | f28b69928983f8c772f40e873ce571379e9fa546 /accel-pppd/triton | |
parent | b997d19f3b6e3087bffb072dd326c4b5311143b5 (diff) | |
download | accel-ppp-xebd-419de8f6910e4fd5d442068ad5ae41b530169470.tar.gz accel-ppp-xebd-419de8f6910e4fd5d442068ad5ae41b530169470.zip |
dynamicaly check if radius module loaded (so not more require to rebuild project without RADIUS to switch to chap-secrets)
Diffstat (limited to 'accel-pppd/triton')
-rw-r--r-- | accel-pppd/triton/loader.c | 48 | ||||
-rw-r--r-- | accel-pppd/triton/triton.h | 2 |
2 files changed, 49 insertions, 1 deletions
diff --git a/accel-pppd/triton/loader.c b/accel-pppd/triton/loader.c index 2a2a2e2..e2faeb2 100644 --- a/accel-pppd/triton/loader.c +++ b/accel-pppd/triton/loader.c @@ -10,12 +10,24 @@ #include "memdebug.h" +struct module_t +{ + struct list_head entry; + char *name; + void *handle; +}; + +static LIST_HEAD(modules); + int load_modules(const char *name) { struct conf_sect_t *sect; struct conf_option_t *opt; char *fname; char *path = MODULE_PATH; + char *ptr1, *ptr2; + struct module_t *m; + void *h; sect = conf_get_section(name); if (!sect) { @@ -48,11 +60,32 @@ int load_modules(const char *name) } } - if (!dlopen(fname, RTLD_LAZY | RTLD_GLOBAL)) { + h = dlopen(fname, RTLD_LAZY | RTLD_GLOBAL); + if (!h) { triton_log_error("loader: failed to load '%s': %s\n", opt->name, dlerror()); _free(fname); return -1; } + + ptr1 = fname; + while (1) { + ptr2 = strchr(ptr1, '/'); + if (!ptr2) + break; + ptr1 = ptr2 + 1; + } + + if (!strncmp(ptr1, "lib", 3)) + ptr1 += 3; + + ptr2 = strstr(ptr1, ".so\x0"); + if (ptr2) + *ptr2 = 0; + + m = _malloc(sizeof(*m)); + m->name = _strdup(ptr1); + m->handle = h; + list_add_tail(&m->entry, &modules); } _free(fname); @@ -60,3 +93,16 @@ int load_modules(const char *name) return 0; } +int __export triton_module_loaded(const char *name) +{ + struct module_t *m; + + list_for_each_entry(m, &modules, entry) { + if (strcmp(m->name, name)) + continue; + return 1; + } + + return 0; +} + diff --git a/accel-pppd/triton/triton.h b/accel-pppd/triton/triton.h index 6866d52..98ef111 100644 --- a/accel-pppd/triton/triton.h +++ b/accel-pppd/triton/triton.h @@ -104,6 +104,8 @@ void triton_conf_reload(void (*notify)(int)); void triton_collect_cpu_usage(void); void triton_stop_collect_cpu_usage(void); +int triton_module_loaded(const char *name); + #define TRITON_OK 0 #define TRITON_ERR_NOCOMP -1 |