Code

dbi utils: Use the new _r interface.
authorSebastian Harl <sh@tokkee.org>
Sat, 26 Apr 2014 21:14:11 +0000 (23:14 +0200)
committerSebastian Harl <sh@tokkee.org>
Sat, 26 Apr 2014 21:14:11 +0000 (23:14 +0200)
src/backend/puppet/store-configs.c
src/utils/dbi.c
t/unit/utils/dbi_test.c

index 0f95ae51e00f22cbca9d11057eaf489b2282e9da..c2f4d084048c71fbccb945b4f38dd753fda24d8d 100644 (file)
@@ -33,8 +33,6 @@
 
 #include "liboconfig/utils.h"
 
-#include <dbi/dbi.h>
-
 #include <assert.h>
 #include <errno.h>
 
@@ -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;
index a2569f7faac01a92b66eb211c3bb543bd2eb0736..de2348e713d34e82924bbf4870d252d186626803 100644 (file)
@@ -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;
index b8a5ea988aee0ad710ba9909835baf1e5359f45a..8a21acebe66f8bd2bcc3007918ecc8888388d386 100644 (file)
@@ -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";