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 str[sizeof(str) - 1] = '\0';
84 strncat(str, parser, sizeof(str) - strlen(str) - 1);
85 ret = load_plugin(str);
89 strncpy(str, "./", sizeof(str));
90 str[sizeof(str) - 1] = '\0';
91 strncat(str, name, sizeof(str) - strlen(str) - 1);
92 strncat(str, parser, sizeof(str) - strlen(str) - 1);
93 ret = load_plugin(str);
100 strncpy(str, exec_path, sizeof(str));
101 str[sizeof(str) - 1] = '\0';
102 strncat(str, "/", sizeof(str) - strlen(str) - 1);
103 strncat(str, name, sizeof(str) - strlen(str) - 1);
104 strncat(str, parser, sizeof(str) - strlen(str) - 1);
105 return load_plugin(str);