summaryrefslogtreecommitdiff
path: root/accel-pptpd/triton/loader.c
blob: a8b9c500e7bf5e1e7c0d71c9f103701a7a3a60e3 (plain)
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
41
42
43
44
45
46
47
48
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <dlfcn.h>

#include "triton_p.h"

#include "memdebug.h"

int load_modules(const char *name)
{
	struct conf_sect_t *sect;
	struct conf_option_t *opt;

	sect = conf_get_section(name);
	if (!sect) {
		fprintf(stderr, "loader: section '%s' not found\n", name);
		return -1;
	}

	char *cwd = getcwd(NULL,0);

	list_for_each_entry(opt, &sect->items, entry) {
		if (!strcmp(opt->name,"path") && opt->val) {
			if (chdir(opt->val)) {
				fprintf(stderr,"loader: chdir '%s': %s\n", opt->val, strerror(errno));
				goto out_err;
			}
			continue;
		}
		if (!dlopen(opt->name, RTLD_NOW | RTLD_GLOBAL)) {
			fprintf(stderr,"loader: failed to load module '%s': %s\n",opt->name, dlerror());
			goto out_err;
		}
	}

	chdir(cwd);
	free(cwd);
	return 0;

out_err:
	chdir(cwd);
	_free(cwd);
	return -1;
}