X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fdbi.c;h=62ef1dc44b4a908b3f75c9cbe4c1f24f495c4663;hp=ac307ff2e01f57f00268c77870c8991b28323892;hb=7111bb6df7628edce3a8e538b386fbe27633a191;hpb=6026e3162e522b133d10596710527d24c2921b55 diff --git a/src/dbi.c b/src/dbi.c index ac307ff2..62ef1dc4 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -62,6 +62,7 @@ struct cdbi_database_s /* {{{ */ { char *name; char *select_db; + char *plugin_name; cdtime_t interval; @@ -107,10 +108,10 @@ static const char *cdbi_strerror(dbi_conn conn, /* {{{ */ msg = NULL; status = dbi_conn_error(conn, &msg); if ((status >= 0) && (msg != NULL)) - ssnprintf(buffer, buffer_size, "%s (status %i)", msg, status); + snprintf(buffer, buffer_size, "%s (status %i)", msg, status); else - ssnprintf(buffer, buffer_size, "dbi_conn_error failed with status %i", - status); + snprintf(buffer, buffer_size, "dbi_conn_error failed with status %i", + status); return buffer; } /* }}} const char *cdbi_conn_error */ @@ -131,12 +132,12 @@ static int cdbi_result_get_field(dbi_result res, /* {{{ */ long long value; value = dbi_result_get_longlong_idx(res, index); - ssnprintf(buffer, buffer_size, "%lli", value); + snprintf(buffer, buffer_size, "%lli", value); } else if (src_type == DBI_TYPE_DECIMAL) { double value; value = dbi_result_get_double_idx(res, index); - ssnprintf(buffer, buffer_size, "%63.15g", value); + snprintf(buffer, buffer_size, "%63.15g", value); } else if (src_type == DBI_TYPE_STRING) { const char *value; @@ -172,7 +173,10 @@ static void cdbi_database_free(cdbi_database_t *db) /* {{{ */ return; sfree(db->name); + sfree(db->select_db); + sfree(db->plugin_name); sfree(db->driver); + sfree(db->host); for (size_t i = 0; i < db->driver_options_num; i++) { sfree(db->driver_options[i].key); @@ -184,7 +188,10 @@ static void cdbi_database_free(cdbi_database_t *db) /* {{{ */ if (db->q_prep_areas) for (size_t i = 0; i < db->queries_num; ++i) udb_query_delete_preparation_area(db->q_prep_areas[i]); - free(db->q_prep_areas); + sfree(db->q_prep_areas); + /* N.B.: db->queries references objects "owned" by the global queries + * variable. Free the array here, but not the content. */ + sfree(db->queries); sfree(db); } /* }}} void cdbi_database_free */ @@ -298,6 +305,8 @@ static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */ status = cf_util_get_string(child, &db->host); else if (strcasecmp("Interval", child->key) == 0) status = cf_util_get_cdtime(child, &db->interval); + else if (strcasecmp("Plugin", child->key) == 0) + status = cf_util_get_string(child, &db->plugin_name); else { WARNING("dbi plugin: Option `%s' not allowed here.", child->key); status = -1; @@ -540,7 +549,8 @@ static int cdbi_read_database_query(cdbi_database_t *db, /* {{{ */ udb_query_prepare_result( q, prep_area, (db->host ? db->host : hostname_g), - /* plugin = */ "dbi", db->name, column_names, column_num, + /* plugin = */ (db->plugin_name != NULL) ? db->plugin_name : "dbi", + db->name, column_names, column_num, /* interval = */ (db->interval > 0) ? db->interval : 0); /* 0 = error; 1 = success; */