6 #include "plugin_manager.h"
11 static char *exec_path;
13 int init_plugin_manager(const char *_exec_path)
15 char *str = strdup(_exec_path);
16 exec_path = strdup(dirname(str));
22 int load_plugin(const char *path)
24 struct plugin_info *info;
28 handle = dlopen(path, RTLD_NOW);
30 pr_err("Failed to load plugin %s: %s\n", path, dlerror());
34 info = dlsym(handle, "plugin_info");
36 pr_err("Plugin %s does not contain plugin info\n", path);
41 pr_err("Plugin %s version info missing\n", path);
46 if (strcmp(RRDD_VERSION, info->version)) {
47 pr_err("Plugin %s version mismatch, expected %s, got %s\n",
48 path, RRDD_VERSION, info->version);
54 pr_err("Plugin info structure has NULL .init callback\n");
59 pr_info("Loading plugin %s %s\n", path,
60 ret ? "failed" : "succeeded");
70 * Try to load a parser plugin with file name matching some of the
71 * following candidates (%s being the requested name):
75 * "<exec_path>/%s_parser.so"
77 int load_parser_plugin(const char *name)
79 char str[256], parser[] = "_parser.so";
82 strncpy(str, name, sizeof(str));
83 strncat(str, parser, sizeof(str) - 1);
84 ret = load_plugin(str);
88 strncpy(str, "./", sizeof(str));
89 strncat(str, name, sizeof(str) - 1);
90 strncat(str, parser, sizeof(str) - 1);
91 ret = load_plugin(str);
98 strncpy(str, exec_path, sizeof(str));
99 strncat(str, "/", sizeof(str) - 1);
100 strncat(str, name, sizeof(str) - 1);
101 strncat(str, parser, sizeof(str) - 1);
102 return load_plugin(str);