From: Sebastian Harl Date: Sat, 26 Apr 2014 21:14:11 +0000 (+0200) Subject: dbi utils: Use the new _r interface. X-Git-Tag: sysdb-0.1.0~79 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1a9933488f9e7babf6c538393cc69c636efca2ed;p=sysdb.git dbi utils: Use the new _r interface. --- diff --git a/src/backend/puppet/store-configs.c b/src/backend/puppet/store-configs.c index 0f95ae5..c2f4d08 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 @@ -383,14 +381,6 @@ 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); - /* 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 a2569f7..de2348e 100644 --- a/src/utils/dbi.c +++ b/src/utils/dbi.c @@ -60,6 +60,7 @@ struct sdb_dbi_client { char *database; dbi_conn conn; + dbi_inst inst; sdb_dbi_options_t *options; }; @@ -263,6 +264,11 @@ sdb_dbi_client_create(const char *driver, const char *database) 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)) { @@ -299,15 +305,15 @@ sdb_dbi_client_connect(sdb_dbi_client_t *client) 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(); @@ -484,6 +490,8 @@ sdb_dbi_client_destroy(sdb_dbi_client_t *client) 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; diff --git a/t/unit/utils/dbi_test.c b/t/unit/utils/dbi_test.c index b8a5ea9..8a21ace 100644 --- a/t/unit/utils/dbi_test.c +++ b/t/unit/utils/dbi_test.c @@ -146,8 +146,20 @@ static mock_query_t *current_query = NULL; /* 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; @@ -155,7 +167,7 @@ dbi_driver_open(const char *name) } /* 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";