summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 98211ed)
raw | patch | inline | side by side (parent: 98211ed)
author | Sebastian Harl <sh@tokkee.org> | |
Fri, 27 Jun 2014 18:11:24 +0000 (20:11 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Fri, 27 Jun 2014 18:15:53 +0000 (20:15 +0200) |
The plugin name (as stored in the plugin context) is used for that purpose,
thus, ensuring that Plugin/Backend blocks will always belong to the respective
LoadPlugin/LoadBackend options of the same name.
thus, ensuring that Plugin/Backend blocks will always belong to the respective
LoadPlugin/LoadBackend options of the same name.
index 8ac829d117c85c5ccae04bba44be92da7aa13c0f..3a41fdf65e0e7d628d9a7e032412fb8f6f9e8649 100644 (file)
sdb_plugin_set_info(info, SDB_PLUGIN_INFO_VERSION, SDB_VERSION);
sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION);
- sdb_plugin_register_config("collectd::unixsock", sdb_collectd_config);
+ sdb_plugin_register_config(sdb_collectd_config);
return 0;
} /* sdb_version_extra */
index e631ae7525acee7c8426563ed51c8531f5825a0f..b6dc1a7d1d810a09ea7ddb4d830c67ff4f85f851 100644 (file)
sdb_plugin_set_info(info, SDB_PLUGIN_INFO_VERSION, SDB_VERSION);
sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION);
- sdb_plugin_register_config("mk-livestatus", sdb_livestatus_config);
+ sdb_plugin_register_config(sdb_livestatus_config);
return 0;
} /* sdb_version_extra */
index c2f4d084048c71fbccb945b4f38dd753fda24d8d..409343fa1f0c33f449ccd969d4155654618e43b3 100644 (file)
sdb_plugin_set_info(info, SDB_PLUGIN_INFO_VERSION, SDB_VERSION);
sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION);
- sdb_plugin_register_config("puppet::store-configs",
- sdb_puppet_stcfg_config);
+ sdb_plugin_register_config(sdb_puppet_stcfg_config);
return 0;
} /* sdb_version_extra */
diff --git a/src/core/plugin.c b/src/core/plugin.c
index b3d5973178dffed19411af5d5acea45a99b718e3..282a5213a45e98cae33ae3c1fde14484972d972a 100644 (file)
--- a/src/core/plugin.c
+++ b/src/core/plugin.c
} /* 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);
index 69c18b41d0ff2cd38d432852d2b1854fee9b8ff8..51d59051e5768ee5e73cb848b216876fadf1238c 100644 (file)
* - a negative value else
*/
int
-sdb_plugin_register_config(const char *name, sdb_plugin_config_cb callback);
+sdb_plugin_register_config(sdb_plugin_config_cb callback);
/*
* sdb_plugin_register_init:
* every plugin care about it.
*
* If non-NULL, sdb_plugin_set_ctx stores the previous context in the location
- * pointed to be 'old'.
+ * pointed to by 'old'.
*/
sdb_plugin_ctx_t
sdb_plugin_get_ctx(void);
/*
* sdb_plugin_configure:
- * Configure the plugin called 'name' (according to the registered config
- * callback) using the config tree 'ci'.
+ * Configure the plugin called 'name' using the config tree 'ci'. The plugin
+ * name is the same as the one used when loading the plugin.
*
* Returns:
* - 0 on success
index 992801d2be80d559b5fcf5f41e6046ac1ad6e1e0..31bfd9bae4375c8ad86507615a010acee09e0943 100644 (file)
{
sdb_plugin_ctx_t ctx = SDB_PLUGIN_CTX_INIT;
- char plugin_name[1024];
+ char plugin_name[1024];
char *name;
int i;
static int
daemon_configure_plugin(oconfig_item_t *ci)
{
+ char plugin_name[1024];
char *name;
assert(ci);
return ERR_INVALID_ARG;
}
- return sdb_plugin_configure(name, ci);
+ if (!strcasecmp(ci->key, "Backend"))
+ snprintf(plugin_name, sizeof(plugin_name), "Backend::%s", name);
+ else
+ strncpy(plugin_name, name, sizeof(plugin_name));
+ return sdb_plugin_configure(plugin_name, ci);
} /* daemon_configure_backend */
static token_parser_t token_parser_list[] = {
index 459a7e2de61f0ebda8670f22e253831402be7127..7e2b4a67dae3fc5e843a1eaf33cd307becc5762c 100644 (file)
sdb_plugin_set_info(info, SDB_PLUGIN_INFO_VERSION, SDB_VERSION);
sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION);
- sdb_plugin_register_config("test::integration::mock", mock_config);
+ sdb_plugin_register_config(mock_config);
return 0;
} /* sdb_module_init */
index 972d246065e2b598972848a11d00d5209f4ce9b1..22bd815a95f4733ef09c52f44b2996b9ca13de13 100755 (executable)
Interval 2
LoadBackend mock_plugin
-<Backend "test::integration::mock">
+<Backend "mock_plugin">
</Backend>
EOF