X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Fbackend%2Fpuppet%2Fstore-configs.c;h=5efc531337c6fd80ab331879397a9a3923e127f7;hp=e109b305819cfcec5fb1d7f32403241ed519d69b;hb=8b3452e508a38e9a28aa82a4636a3dbe03d32e65;hpb=c9ed4d2a7a92ef589809a7df9b04c061afa4ef64 diff --git a/src/backend/puppet/store-configs.c b/src/backend/puppet/store-configs.c index e109b30..5efc531 100644 --- a/src/backend/puppet/store-configs.c +++ b/src/backend/puppet/store-configs.c @@ -33,8 +33,6 @@ #include "liboconfig/utils.h" -#include - #include #include @@ -74,7 +72,7 @@ sdb_puppet_stcfg_get_hosts(sdb_dbi_client_t __attribute__((unused)) *client, else if (! status) sdb_log(SDB_LOG_DEBUG, "puppet::store-configs backend: " "Added/updated host '%s' (last update timestamp = " - "%"PRIscTIME").", hostname, timestamp); + "%"PRIsdbTIME").", hostname, timestamp); return 0; } /* sdb_puppet_stcfg_get_hosts */ @@ -138,6 +136,17 @@ sdb_puppet_stcfg_init(sdb_object_t *user_data) return 0; } /* sdb_puppet_stcfg_init */ +static int +sdb_puppet_stcfg_shutdown(sdb_object_t *user_data) +{ + if (! user_data) + return -1; + + sdb_dbi_client_destroy(SDB_OBJ_WRAPPER(user_data)->data); + SDB_OBJ_WRAPPER(user_data)->data = NULL; + return 0; +} /* sdb_puppet_stcfg_shutdown */ + static int sdb_puppet_stcfg_collect(sdb_object_t *user_data) { @@ -185,7 +194,6 @@ static int sdb_puppet_stcfg_config_conn(oconfig_item_t *ci) { char *name = NULL; - char cb_name[1024]; sdb_object_t *user_data; sdb_dbi_client_t *client; @@ -306,9 +314,6 @@ sdb_puppet_stcfg_config_conn(oconfig_item_t *ci) return -1; } - snprintf(cb_name, sizeof(cb_name), "puppet::storeconfigs::%s", name); - cb_name[sizeof(cb_name) - 1] = '\0'; - client = sdb_dbi_client_create(driver, database); if (! client) { char errbuf[1024]; @@ -329,8 +334,10 @@ sdb_puppet_stcfg_config_conn(oconfig_item_t *ci) return -1; } - sdb_plugin_register_init(cb_name, sdb_puppet_stcfg_init, user_data); - sdb_plugin_register_collector(cb_name, sdb_puppet_stcfg_collect, + sdb_plugin_register_init(name, sdb_puppet_stcfg_init, user_data); + sdb_plugin_register_shutdown(name, sdb_puppet_stcfg_shutdown, + user_data); + sdb_plugin_register_collector(name, sdb_puppet_stcfg_collect, /* interval */ NULL, user_data); /* pass control to the list */ @@ -343,6 +350,9 @@ sdb_puppet_stcfg_config(oconfig_item_t *ci) { int i; + if (! ci) /* nothing to do to deconfigure this plugin */ + return 0; + for (i = 0; i < ci->children_num; ++i) { oconfig_item_t *child = ci->children + i; @@ -358,7 +368,6 @@ sdb_puppet_stcfg_config(oconfig_item_t *ci) int sdb_module_init(sdb_plugin_info_t *info) { - sdb_plugin_set_info(info, SDB_PLUGIN_INFO_NAME, "puppet::store-configs"); sdb_plugin_set_info(info, SDB_PLUGIN_INFO_DESC, "backend accessing the Puppet stored configuration database"); sdb_plugin_set_info(info, SDB_PLUGIN_INFO_COPYRIGHT, @@ -367,15 +376,7 @@ sdb_module_init(sdb_plugin_info_t *info) sdb_plugin_set_info(info, SDB_PLUGIN_INFO_VERSION, SDB_VERSION); sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION); - if (dbi_initialize(/* driver dir = */ NULL) < 0) { - sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: failed to " - "initialize DBI; possibly you don't have any drivers " - "installed."); - return -1; - } - - sdb_plugin_register_config("puppet::store-configs", - sdb_puppet_stcfg_config); + sdb_plugin_register_config(sdb_puppet_stcfg_config); return 0; } /* sdb_version_extra */