diff --git a/src/core/plugin.c b/src/core/plugin.c
index 873e64a19436903c379bff983565c825008f2a43..282a5213a45e98cae33ae3c1fde14484972d972a 100644 (file)
--- a/src/core/plugin.c
+++ b/src/core/plugin.c
} /* module_init */
static int
-module_load(const char *name, const sdb_plugin_ctx_t *plugin_ctx)
+module_load(const char *basedir, const char *name,
+ const sdb_plugin_ctx_t *plugin_ctx)
{
char base_name[name ? strlen(name) + 1 : 1];
const char *name_ptr;
int status;
+ assert(name);
+
base_name[0] = '\0';
name_ptr = name;
}
strcat(base_name, name_ptr);
- snprintf(filename, sizeof(filename), "%s/%s.so",
- PKGLIBDIR, base_name);
+ if (! basedir)
+ basedir = PKGLIBDIR;
+
+ snprintf(filename, sizeof(filename), "%s/%s.so", basedir, base_name);
filename[sizeof(filename) - 1] = '\0';
if (access(filename, R_OK)) {
*/
int
-sdb_plugin_load(const char *name, const sdb_plugin_ctx_t *plugin_ctx)
+sdb_plugin_load(const char *basedir, const char *name,
+ const sdb_plugin_ctx_t *plugin_ctx)
{
ctx_t *ctx;
return 0;
}
- return module_load(name, plugin_ctx);
+ return module_load(basedir, name, plugin_ctx);
} /* sdb_plugin_load */
int
} /* sdb_plugin_set_info */
int
-sdb_plugin_register_config(const char *name, sdb_plugin_config_cb callback)
+sdb_plugin_register_config(sdb_plugin_config_cb callback)
{
- return plugin_add_callback(&config_list, "init", name,
+ ctx_t *ctx = ctx_get();
+
+ if (! ctx) {
+ sdb_log(SDB_LOG_ERR, "core: Invalid attempt to register a "
+ "config callback from outside a plugin");
+ return -1;
+ }
+ return plugin_add_callback(&config_list, "init", ctx->info.plugin_name,
(void *)callback, NULL);
} /* sdb_plugin_register_config */
if (! plugin) {
ctx_t *ctx = CTX(sdb_llist_search_by_name(all_plugins, name));
if (! ctx)
- sdb_log(SDB_LOG_ERR, "core: Plugin '%s' not loaded.", name);
+ sdb_log(SDB_LOG_ERR, "core: Cannot configure unknown "
+ "plugin '%s'. Missing 'LoadPlugin \"%s\"'?",
+ name, name);
else
sdb_log(SDB_LOG_ERR, "core: Plugin '%s' did not register "
"a config callback.", name);
return ret;
} /* sdb_plugin_init_all */
+int
+sdb_plugin_shutdown_all(void)
+{
+ sdb_llist_iter_t *iter;
+ int ret = 0;
+
+ iter = sdb_llist_get_iter(shutdown_list);
+ while (sdb_llist_iter_has_next(iter)) {
+ sdb_plugin_cb_t *cb;
+ sdb_plugin_shutdown_cb callback;
+ ctx_t *old_ctx;
+
+ sdb_object_t *obj = sdb_llist_iter_get_next(iter);
+ assert(obj);
+ cb = SDB_PLUGIN_CB(obj);
+
+ callback = (sdb_plugin_shutdown_cb)cb->cb_callback;
+
+ old_ctx = ctx_set(cb->cb_ctx);
+ if (callback(cb->cb_user_data)) {
+ sdb_log(SDB_LOG_ERR, "core: Failed to shutdown plugin '%s'.",
+ obj->name);
+ ++ret;
+ }
+ ctx_set(old_ctx);
+ }
+ sdb_llist_iter_destroy(iter);
+ return ret;
+} /* sdb_plugin_shutdown_all */
+
int
sdb_plugin_collector_loop(sdb_plugin_loop_t *loop)
{
sdb_log(SDB_LOG_ERR, "core: Failed to sleep "
"in collector main loop: %s",
sdb_strerror(errno, errbuf, sizeof(errbuf)));
+ sdb_llist_insert_sorted(collector_list, obj,
+ plugin_cmp_next_update);
+ sdb_object_deref(obj);
return -1;
}
errno = 0;
}
- if (! loop->do_loop)
+ if (! loop->do_loop) {
+ /* put back; don't worry about errors */
+ sdb_llist_insert_sorted(collector_list, obj,
+ plugin_cmp_next_update);
+ sdb_object_deref(obj);
return 0;
+ }
}
old_ctx = ctx_set(SDB_PLUGIN_CCB(obj)->ccb_ctx);
sdb_llist_iter_t *iter;
int ret = -1;
+ _Bool logged = 0;
+
if (! msg)
return 0;
- if (! sdb_llist_len(log_list))
- return fprintf(stderr, "[%s] %s\n", SDB_LOG_PRIO_TO_STRING(prio), msg);
-
iter = sdb_llist_get_iter(log_list);
while (sdb_llist_iter_has_next(iter)) {
sdb_plugin_log_cb callback;
tmp = callback(prio, msg, SDB_PLUGIN_CB(obj)->cb_user_data);
if (tmp > ret)
ret = tmp;
+
+ if (SDB_PLUGIN_CB(obj)->cb_ctx)
+ logged = 1;
+ /* else: this is an internally registered callback */
}
sdb_llist_iter_destroy(iter);
+
+ if (! logged)
+ return fprintf(stderr, "[%s] %s\n", SDB_LOG_PRIO_TO_STRING(prio), msg);
return ret;
} /* sdb_plugin_log */