X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fdbi.c;h=c851ba2b121dc272874e513a18eb26ea888178e7;hb=1b4d95b869063e619bd7aae54cf37c5a1b91fbee;hp=779c723f91741de5f5db273993a4929a1bcb2a78;hpb=f2106c1e8c35c24e274f5ec08b70e967ade27ba4;p=collectd.git diff --git a/src/dbi.c b/src/dbi.c index 779c723f..c851ba2b 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -1,19 +1,24 @@ /** * 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 - * Free Software Foundation; only version 2 of the License is applicable. + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: * Florian octo Forster @@ -27,6 +32,18 @@ #include +/* 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 */ @@ -63,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; @@ -331,6 +351,7 @@ static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */ while ((status == 0) && (db->queries_num > 0)) { + size_t j; db->q_prep_areas = (udb_query_preparation_area_t **) calloc ( db->queries_num, sizeof (*db->q_prep_areas)); @@ -341,12 +362,12 @@ static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */ break; } - for (i = 0; i < db->queries_num; ++i) + for (j = 0; j < db->queries_num; ++j) { - db->q_prep_areas[i] - = udb_query_allocate_preparation_area (db->queries[i]); + db->q_prep_areas[j] + = udb_query_allocate_preparation_area (db->queries[j]); - if (db->q_prep_areas[i] == NULL) + if (db->q_prep_areas[j] == NULL) { WARNING ("dbi plugin: udb_query_allocate_preparation_area failed"); status = -1; @@ -386,7 +407,7 @@ static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */ plugin_register_complex_read (/* group = */ NULL, /* name = */ name ? name : db->name, /* callback = */ cdbi_read_database, - /* interval = */ NULL, + /* interval = */ 0, /* user_data = */ &ud); free (name); } @@ -446,20 +467,20 @@ static int cdbi_init (void) /* {{{ */ 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); @@ -667,16 +688,16 @@ static int cdbi_connect_database (cdbi_database_t *db) /* {{{ */ 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)); }