summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d14f0e3)
raw | patch | inline | side by side (parent: d14f0e3)
author | Florian Forster <octo@collectd.org> | |
Thu, 26 Feb 2015 11:16:00 +0000 (12:16 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Thu, 26 Feb 2015 11:16:00 +0000 (12:16 +0100) |
Macros are in place to make buliding with libdbi <0.9.0 possible.
Fixes: #950
Fixes: #950
src/dbi.c | patch | blob | history |
diff --git a/src/dbi.c b/src/dbi.c
index 80488d8478f6df99c748de2e4e39e872b1236701..2d3f566f1f6fc7f52a0e76a3b0bec7945619c77c 100644 (file)
--- a/src/dbi.c
+++ b/src/dbi.c
/**
* collectd - src/dbi.c
- * Copyright (C) 2008-2013 Florian octo Forster
+ * Copyright (C) 2008-2015 Florian octo Forster
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
#include <dbi/dbi.h>
+/* libdbi 0.9.0 introduced a new thread-safe interface and marked the old
+ * functions "deprecated". These macros convert the new functions to their old
+ * counterparts for backwards compatibility. */
+#if !defined(LIBDBI_VERSION) || (LIBDBI_VERSION < 900)
+# define HAVE_LEGACY_LIBDBI 1
+# define dbi_initialize_r(a,inst) dbi_initialize(a)
+# define dbi_shutdown_r(inst) dbi_shutdown()
+# define dbi_set_verbosity_r(a,inst) dbi_set_verbosity(a)
+# define dbi_driver_list_r(a,inst) dbi_driver_list(a)
+# define dbi_driver_open_r(a,inst) dbi_driver_open(a)
+#endif
+
/*
* Data types
*/
/*
* Global variables
*/
+#if !defined(HAVE_LEGACY_LIBDBI) || !HAVE_LEGACY_LIBDBI
+static dbi_inst dbi_instance = 0;
+#endif
static udb_query_t **queries = NULL;
static size_t queries_num = 0;
static cdbi_database_t **databases = NULL;
return (-1);
}
- status = dbi_initialize (NULL);
+ status = dbi_initialize_r (/* driverdir = */ NULL, &dbi_instance);
if (status < 0)
{
- ERROR ("dbi plugin: cdbi_init: dbi_initialize failed with status %i.",
+ ERROR ("dbi plugin: cdbi_init: dbi_initialize_r failed with status %i.",
status);
return (-1);
}
else if (status == 0)
{
- ERROR ("dbi plugin: `dbi_initialize' could not load any drivers. Please "
+ ERROR ("dbi plugin: `dbi_initialize_r' could not load any drivers. Please "
"install at least one `DBD' or check your installation.");
return (-1);
}
- DEBUG ("dbi plugin: cdbi_init: dbi_initialize reports %i driver%s.",
+ DEBUG ("dbi plugin: cdbi_init: dbi_initialize_r reports %i driver%s.",
status, (status == 1) ? "" : "s");
return (0);
db->connection = NULL;
}
- driver = dbi_driver_open (db->driver);
+ driver = dbi_driver_open_r (db->driver, dbi_instance);
if (driver == NULL)
{
- ERROR ("dbi plugin: cdbi_connect_database: dbi_driver_open (%s) failed.",
+ ERROR ("dbi plugin: cdbi_connect_database: dbi_driver_open_r (%s) failed.",
db->driver);
INFO ("dbi plugin: Maybe the driver isn't installed? "
"Known drivers are:");
- for (driver = dbi_driver_list (NULL);
+ for (driver = dbi_driver_list_r (NULL, dbi_instance);
driver != NULL;
- driver = dbi_driver_list (driver))
+ driver = dbi_driver_list_r (driver, dbi_instance))
{
INFO ("dbi plugin: * %s", dbi_driver_get_name (driver));
}
int success = 0;
int status;
+ /* TODO(octo): Starting with libdbi 0.9.0, there is an "instance" argument to
+ * the *_r-functions. We should probably have multiple read callbacks instead
+ * of this loop. */
for (i = 0; i < databases_num; i++)
{
status = cdbi_read_database (databases[i]);