6 #include "plugin_manager.h"
12 static char *exec_path;
14 int init_plugin_manager(const char *_exec_path)
16 char *str = strdup(_exec_path);
17 exec_path = strdup(dirname(str));
23 int load_plugin(const char *path)
25 struct plugin_info *info;
29 handle = dlopen(path, RTLD_NOW);
31 pr_err("Failed to load plugin %s: %s\n", path, dlerror());
35 info = dlsym(handle, "plugin_info");
37 pr_err("Plugin %s does not contain plugin info\n", path);
42 pr_err("Plugin %s version info missing\n", path);
47 if (strcmp(RRDD_VERSION, info->version)) {
48 pr_err("Plugin %s version mismatch, expected %s, got %s\n",
49 path, RRDD_VERSION, info->version);
55 pr_err("Plugin info structure has NULL .init callback\n");
60 pr_info("Loading plugin %s %s\n", path,
61 ret ? "failed" : "succeeded");
71 * Try to load a parser plugin with file name matching some of the
72 * following candidates (%s being the requested name):
76 * "<exec_path>/%s_parser.so"
78 int load_parser_plugin(const char *name)
80 char str[256], parser[] = "_parser.so";
83 strncpy(str, name, sizeof(str));
84 str[sizeof(str) - 1] = '\0';
85 _strlcat(str, parser, sizeof(str));
86 ret = load_plugin(str);
90 strncpy(str, "./", sizeof(str));
91 str[sizeof(str) - 1] = '\0';
92 _strlcat(str, name, sizeof(str));
93 _strlcat(str, parser, sizeof(str));
94 ret = load_plugin(str);
101 strncpy(str, exec_path, sizeof(str));
102 str[sizeof(str) - 1] = '\0';
103 _strlcat(str, "/", sizeof(str));
104 _strlcat(str, name, sizeof(str));
105 _strlcat(str, parser, sizeof(str));
106 return load_plugin(str);