X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdbi.c;h=a7963ea223371f5d70a4ef63f2d0a3a6263db22a;hb=f2daf5deea1d50dbb834cffa0c8106b5456c9d82;hp=223e159f3f9ab88293a8a7edd4d68df1bc661459;hpb=446a764be3e33b6fa48b93049751c051724ee650;p=collectd.git diff --git a/src/dbi.c b/src/dbi.c index 223e159f..a7963ea2 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -1,6 +1,6 @@ /** * collectd - src/dbi.c - * Copyright (C) 2008-2013 Florian octo Forster + * Copyright (C) 2008-2015 Florian octo Forster * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -32,9 +32,18 @@ #include -#ifdef HAVE_LIBDBI_R - dbi_inst inst = NULL; +/* 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 */ @@ -71,6 +80,9 @@ typedef struct cdbi_database_s cdbi_database_t; /* }}} */ /* * 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; @@ -134,7 +146,7 @@ static int cdbi_result_get_field (dbi_result res, /* {{{ */ else if (src_type == DBI_TYPE_STRING) { const char *value; - + value = dbi_result_get_string_idx (res, index); if (value == NULL) sstrncpy (buffer, "", buffer_size); @@ -200,7 +212,7 @@ static void cdbi_database_free (cdbi_database_t *db) /* {{{ */ * * ... * - * + * * * Driver "mysql" * DriverOption "hostname" "localhost" @@ -454,24 +466,20 @@ static int cdbi_init (void) /* {{{ */ return (-1); } -#ifdef HAVE_LIBDBI_R - status = dbi_initialize_r (NULL, &inst); -#else - status = dbi_initialize (NULL); -#endif + 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); @@ -679,26 +687,16 @@ static int cdbi_connect_database (cdbi_database_t *db) /* {{{ */ db->connection = NULL; } -#ifdef HAVE_LIBDBI_R - driver = dbi_driver_open_r (db->driver, inst); -#else - driver = dbi_driver_open (db->driver); -#endif + 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:"); -#ifdef HAVE_LIBDBI_R - for (driver = dbi_driver_list_r (NULL, inst); + for (driver = dbi_driver_list_r (NULL, dbi_instance); driver != NULL; - driver = dbi_driver_list_r (driver, inst)) -#else - for (driver = dbi_driver_list (NULL); - driver != NULL; - driver = dbi_driver_list (driver)) -#endif + driver = dbi_driver_list_r (driver, dbi_instance)) { INFO ("dbi plugin: * %s", dbi_driver_get_name (driver)); }