index 601bc06d9a9e231f4671aa3e059760639c0fb892..a9a0ff777e9d6f35bd364885832b485d1f88beef 100644 (file)
#include "sysdb.h"
#include "core/plugin.h"
#include "core/store.h"
-#include "utils/error.h"
#include "utils/dbi.h"
+#include "utils/error.h"
#include "liboconfig/utils.h"
size_t n, sdb_data_t *data,
sdb_object_t __attribute__((unused)) *user_data)
{
- sdb_host_t host = SDB_HOST_INIT;
+ const char *hostname;
+ sdb_time_t timestamp;
int status;
assert((data[0].type == SDB_TYPE_STRING)
&& (data[1].type == SDB_TYPE_DATETIME));
- host.host_name = strdup(data[0].data.string);
- host.host_last_update = data[1].data.datetime;
+ hostname = data[0].data.string;
+ timestamp = data[1].data.datetime;
- status = sdb_store_host(&host);
+ status = sdb_store_host(hostname, timestamp);
if (status < 0) {
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: Failed to "
- "store/update host '%s'.\n", host.host_name);
- free(host.host_name);
+ "store/update host '%s'.", hostname);
return -1;
}
else if (! status)
sdb_log(SDB_LOG_DEBUG, "puppet::store-configs backend: "
"Added/updated host '%s' (last update timestamp = "
- "%"PRIscTIME").\n", host.host_name, host.host_last_update);
- free(host.host_name);
+ "%"PRIscTIME").", hostname, timestamp);
return 0;
} /* sdb_puppet_stcfg_get_hosts */
size_t n, sdb_data_t *data,
sdb_object_t __attribute__((unused)) *user_data)
{
- sdb_attribute_t attr = SDB_ATTR_INIT;
-
int status;
+ const char *hostname;
+ const char *key;
+ const char *value;
+ sdb_time_t last_update;
+
assert(n == 4);
assert((data[0].type == SDB_TYPE_STRING)
&& (data[1].type == SDB_TYPE_STRING)
&& (data[2].type == SDB_TYPE_STRING)
&& (data[3].type == SDB_TYPE_DATETIME));
- attr.hostname = strdup(data[0].data.string);
- attr.attr_name = strdup(data[1].data.string);
- attr.attr_value = strdup(data[2].data.string);
- attr.attr_last_update = data[3].data.datetime;
+ hostname = data[0].data.string;
+ key = data[1].data.string;
+ value = data[2].data.string;
+ last_update = data[3].data.datetime;
- status = sdb_store_attribute(&attr);
+ status = sdb_store_attribute(hostname, key, value, last_update);
if (status < 0) {
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: Failed to "
- "store/update host attribute '%s' for host '%s'.\n",
- attr.attr_name, attr.hostname);
- free(attr.hostname);
- free(attr.attr_name);
- free(attr.attr_value);
+ "store/update host attribute '%s' for host '%s'.",
+ key, hostname);
return -1;
}
- free(attr.hostname);
- free(attr.attr_name);
- free(attr.attr_value);
return 0;
} /* sdb_puppet_stcfg_get_attrs */
client = SDB_OBJ_WRAPPER(user_data)->data;
if (sdb_dbi_client_connect(client)) {
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: "
- "Failed to connect to the storeconfigs DB.\n");
+ "Failed to connect to the storeconfigs DB.");
return -1;
}
sdb_log(SDB_LOG_INFO, "puppet::store-configs backend: Successfully "
- "connected to the storeconfigs DB.\n");
+ "connected to the storeconfigs DB.");
return 0;
} /* sdb_puppet_stcfg_init */
client = SDB_OBJ_WRAPPER(user_data)->data;
if (sdb_dbi_client_check_conn(client)) {
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: "
- "Connection to storeconfigs DB failed.\n");
+ "Connection to storeconfigs DB failed.");
return -1;
}
sdb_puppet_stcfg_get_hosts, NULL, /* #columns = */ 2,
/* col types = */ SDB_TYPE_STRING, SDB_TYPE_DATETIME)) {
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: Failed to "
- "retrieve hosts from the storeconfigs DB.\n");
+ "retrieve hosts from the storeconfigs DB.");
return -1;
}
/* col types = */ SDB_TYPE_STRING, SDB_TYPE_STRING,
SDB_TYPE_STRING, SDB_TYPE_DATETIME)) {
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: Failed to "
- "retrieve host attributes from the storeconfigs DB.\n");
+ "retrieve host attributes from the storeconfigs DB.");
return -1;
}
return 0;
if (oconfig_get_string(ci, &name)) {
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: Connection "
"requires a single string argument\n"
- "\tUsage: <Connection NAME>\n");
+ "\tUsage: <Connection NAME>");
return -1;
}
if (oconfig_get_string(child, &driver)) {
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: "
"DBAdapter requires a single string argument inside "
- "<Connection %s>\n\tUsage: DBAdapter NAME\n",
+ "<Connection %s>\n\tUsage: DBAdapter NAME",
name);
}
continue;
if (oconfig_get_string(child, &database)) {
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: "
"DBName requires a single string argument inside "
- "<Connection %s>\n\tUsage: DBName NAME\n",
+ "<Connection %s>\n\tUsage: DBName NAME",
name);
}
continue;
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: "
"DBIOption requires exactly two string arguments "
"inside <Connection %s>\n"
- "\tUsage: DBIOption KEY VALUE\n", name);
+ "\tUsage: DBIOption KEY VALUE", name);
continue;
}
else {
sdb_log(SDB_LOG_WARNING, "puppet::store-configs backend: "
"Ignoring unknown config option '%s' inside "
- "<Connection %s>.\n", child->key, name);
+ "<Connection %s>.", child->key, name);
continue;
}
if (status) {
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: Option "
"'%s' requires a single string argument inside "
- "<Connection %s>\n\tUsage: DBAdapter NAME\n",
+ "<Connection %s>\n\tUsage: DBAdapter NAME",
child->key, name);
continue;
}
if (! (options = sdb_dbi_options_create())) {
char errmsg[1024];
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: "
- "Failed to create DBI options object: %s\n",
+ "Failed to create DBI options object: %s",
sdb_strerror(errno, errmsg, sizeof(errmsg)));
continue;
}
if (sdb_dbi_options_add(options, key, value)) {
char errmsg[1024];
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: "
- "Failed to add option '%s': %s\n", key,
+ "Failed to add option '%s': %s", key,
sdb_strerror(errno, errmsg, sizeof(errmsg)));
continue;
}
if (! driver) {
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: "
- "Connection '%s' " "missing the 'DBAdapter' option.\n",
+ "Connection '%s' " "missing the 'DBAdapter' option.",
name);
return -1;
}
if (! database) {
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: "
- "Connection '%s' missing the 'DBName' option.\n", name);
+ "Connection '%s' missing the 'DBName' option.", name);
return -1;
}
if (! client) {
char errbuf[1024];
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: "
- "Failed to create DBI client: %s\n",
+ "Failed to create DBI client: %s",
sdb_strerror(errno, errbuf, sizeof(errbuf)));
return -1;
}
sdb_dbi_client_set_options(client, options);
- user_data = sdb_object_create_wrapper(client,
+ user_data = sdb_object_create_wrapper("dbi-client", client,
(void (*)(void *))sdb_dbi_client_destroy);
if (! user_data) {
sdb_dbi_client_destroy(client);
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: "
- "Failed to allocate sdb_object_t\n");
+ "Failed to allocate sdb_object_t");
return -1;
}
sdb_puppet_stcfg_config_conn(child);
else
sdb_log(SDB_LOG_WARNING, "puppet::store-configs backend: "
- "Ignoring unknown config option '%s'.\n", child->key);
+ "Ignoring unknown config option '%s'.", child->key);
}
return 0;
} /* sdb_puppet_stcfg_config */
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.\n");
+ "installed.");
return -1;
}