summaryrefslogtreecommitdiff
path: root/accel-pptpd/triton/loader.c
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2010-10-06 16:55:05 +0400
committerKozlov Dmitry <dima@server>2010-10-06 16:55:05 +0400
commit45b3c9c5bdd896f51f47e29069e3c030ddb17d51 (patch)
treecbec5824ffb2eee20b98ad9892a357304384ff01 /accel-pptpd/triton/loader.c
parentba3db9f17477ea4b49c266c5cb50f63f3b074db2 (diff)
parent01ccd98495c9da1e79f7867bf52416b23f20200d (diff)
downloadaccel-ppp-45b3c9c5bdd896f51f47e29069e3c030ddb17d51.tar.gz
accel-ppp-45b3c9c5bdd896f51f47e29069e3c030ddb17d51.zip
merged branch accel-pptpd
Diffstat (limited to 'accel-pptpd/triton/loader.c')
-rw-r--r--accel-pptpd/triton/loader.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/accel-pptpd/triton/loader.c b/accel-pptpd/triton/loader.c
new file mode 100644
index 00000000..b6c1914e
--- /dev/null
+++ b/accel-pptpd/triton/loader.c
@@ -0,0 +1,62 @@
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <dlfcn.h>
+#include <limits.h>
+
+#include "triton_p.h"
+
+#include "memdebug.h"
+
+int load_modules(const char *name)
+{
+ struct conf_sect_t *sect;
+ struct conf_option_t *opt;
+ char *fname;
+ char *path = MODULE_PATH;
+
+ sect = conf_get_section(name);
+ if (!sect) {
+ fprintf(stderr, "loader: section '%s' not found\n", name);
+ return -1;
+ }
+
+ fname = _malloc(PATH_MAX);
+
+ list_for_each_entry(opt, &sect->items, entry) {
+ if (!strcmp(opt->name,"path") && opt->val) {
+ path = opt->val;
+ continue;
+ }
+
+ strcpy(fname, path);
+ strcat(fname, "/");
+ strcat(fname, opt->name);
+ if (access(fname, F_OK)) {
+ strcpy(fname, path);
+ strcat(fname, "/lib");
+ strcat(fname, opt->name);
+ strcat(fname, ".so");
+ if (access(fname, F_OK)) {
+ strcpy(fname, opt->name);
+ if (access(opt->name, F_OK)) {
+ triton_log_error("loader: '%s' not found\n", opt->name);
+ continue;
+ }
+ }
+ }
+
+ if (!dlopen(fname, RTLD_NOW | RTLD_GLOBAL)) {
+ triton_log_error("loader: failed to load '%s': %s\n", opt->name, dlerror());
+ _free(fname);
+ return -1;
+ }
+ }
+
+ _free(fname);
+
+ return 0;
+}
+