summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cf17313)
raw | patch | inline | side by side (parent: cf17313)
author | Sebastian Harl <sh@tokkee.org> | |
Sat, 26 Apr 2014 21:14:11 +0000 (23:14 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sat, 26 Apr 2014 21:14:11 +0000 (23:14 +0200) |
src/backend/puppet/store-configs.c | patch | blob | history | |
src/utils/dbi.c | patch | blob | history | |
t/unit/utils/dbi_test.c | patch | blob | history |
index 0f95ae51e00f22cbca9d11057eaf489b2282e9da..c2f4d084048c71fbccb945b4f38dd753fda24d8d 100644 (file)
#include "liboconfig/utils.h"
-#include <dbi/dbi.h>
-
#include <assert.h>
#include <errno.h>
sdb_plugin_set_info(info, SDB_PLUGIN_INFO_VERSION, SDB_VERSION);
sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION);
- /* don't reinitialize dbi when reinitializing the plugin */
- if (info && (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);
return 0;
diff --git a/src/utils/dbi.c b/src/utils/dbi.c
index a2569f7faac01a92b66eb211c3bb543bd2eb0736..de2348e713d34e82924bbf4870d252d186626803 100644 (file)
--- a/src/utils/dbi.c
+++ b/src/utils/dbi.c
char *database;
dbi_conn conn;
+ dbi_inst inst;
sdb_dbi_options_t *options;
};
client->conn = NULL;
client->options = NULL;
+ if (dbi_initialize_r(/* driverdir = */ NULL, &client->inst) < 0) {
+ free(client);
+ return NULL;
+ }
+
client->driver = strdup(driver);
client->database = strdup(database);
if ((! client->driver) || (! client->database)) {
client->conn = NULL;
}
- driver = dbi_driver_open(client->driver);
+ driver = dbi_driver_open_r(client->driver, client->inst);
if (! driver) {
sdb_error_set("dbi: failed to open DBI driver '%s'; "
"possibly it's not installed.\n",
client->driver);
sdb_error_append("dbi: known drivers:\n");
- for (driver = dbi_driver_list(NULL); driver;
- driver = dbi_driver_list(driver)) {
+ for (driver = dbi_driver_list_r(NULL, client->inst); driver;
+ driver = dbi_driver_list_r(driver, client->inst)) {
sdb_error_append("\t- %s\n", dbi_driver_get_name(driver));
}
sdb_error_chomp();
dbi_conn_close(client->conn);
client->conn = NULL;
+ dbi_shutdown_r(client->inst);
+
if (client->options)
sdb_dbi_options_destroy(client->options);
client->options = NULL;
index b8a5ea988aee0ad710ba9909835baf1e5359f45a..8a21acebe66f8bd2bcc3007918ecc8888388d386 100644 (file)
--- a/t/unit/utils/dbi_test.c
+++ b/t/unit/utils/dbi_test.c
/* dbi_driver, dbi_conn, dbi_result are void pointers */
+int
+dbi_initialize_r(const char __attribute__((unused)) *driverdir,
+ dbi_inst __attribute__((unused)) *pInst)
+{
+ return 0;
+} /* dbi_initialize_r */
+
+void
+dbi_shutdown_r(dbi_inst __attribute__((unused)) inst)
+{
+} /* dbi_shutdown_r */
+
dbi_driver
-dbi_driver_open(const char *name)
+dbi_driver_open_r(const char *name, dbi_inst __attribute__((unused)) inst)
{
if (strcmp(name, "mockdriver"))
return NULL;
} /* dbi_driver_open */
dbi_driver
-dbi_driver_list(dbi_driver curr)
+dbi_driver_list_r(dbi_driver curr, dbi_inst __attribute__((unused)) inst)
{
if (!curr)
return "mockdriver";