projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'collectd-5.7'
[collectd.git]
/
src
/
dbi.c
diff --git
a/src/dbi.c
b/src/dbi.c
index
7cab1d5
..
a577aef
100644
(file)
--- a/
src/dbi.c
+++ b/
src/dbi.c
@@
-101,18
+101,18
@@
static const char *cdbi_strerror(dbi_conn conn, /* {{{ */
if (conn == NULL) {
sstrncpy(buffer, "connection is NULL", buffer_size);
if (conn == NULL) {
sstrncpy(buffer, "connection is NULL", buffer_size);
- return
(buffer)
;
+ return
buffer
;
}
msg = NULL;
status = dbi_conn_error(conn, &msg);
if ((status >= 0) && (msg != NULL))
}
msg = NULL;
status = dbi_conn_error(conn, &msg);
if ((status >= 0) && (msg != NULL))
- s
s
nprintf(buffer, buffer_size, "%s (status %i)", msg, status);
+ snprintf(buffer, buffer_size, "%s (status %i)", msg, status);
else
else
- s
s
nprintf(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)
;
+ return
buffer
;
} /* }}} const char *cdbi_conn_error */
static int cdbi_result_get_field(dbi_result res, /* {{{ */
} /* }}} const char *cdbi_conn_error */
static int cdbi_result_get_field(dbi_result res, /* {{{ */
@@
-124,19
+124,19
@@
static int cdbi_result_get_field(dbi_result res, /* {{{ */
if (src_type == DBI_TYPE_ERROR) {
ERROR("dbi plugin: cdbi_result_get: "
"dbi_result_get_field_type_idx failed.");
if (src_type == DBI_TYPE_ERROR) {
ERROR("dbi plugin: cdbi_result_get: "
"dbi_result_get_field_type_idx failed.");
- return
(-1)
;
+ return
-1
;
}
if (src_type == DBI_TYPE_INTEGER) {
long long value;
value = dbi_result_get_longlong_idx(res, index);
}
if (src_type == DBI_TYPE_INTEGER) {
long long value;
value = dbi_result_get_longlong_idx(res, index);
- s
s
nprintf(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);
} else if (src_type == DBI_TYPE_DECIMAL) {
double value;
value = dbi_result_get_double_idx(res, index);
- s
s
nprintf(buffer, buffer_size, "%63.15g", value);
+ snprintf(buffer, buffer_size, "%63.15g", value);
} else if (src_type == DBI_TYPE_STRING) {
const char *value;
} else if (src_type == DBI_TYPE_STRING) {
const char *value;
@@
-144,7
+144,7
@@
static int cdbi_result_get_field(dbi_result res, /* {{{ */
if (value == NULL)
sstrncpy(buffer, "", buffer_size);
else if (strcmp("ERROR", value) == 0)
if (value == NULL)
sstrncpy(buffer, "", buffer_size);
else if (strcmp("ERROR", value) == 0)
- return
(-1)
;
+ return
-1
;
else
sstrncpy(buffer, value, buffer_size);
}
else
sstrncpy(buffer, value, buffer_size);
}
@@
-160,10
+160,10
@@
static int cdbi_result_get_field(dbi_result res, /* {{{ */
ERROR("dbi plugin: Column `%s': Don't know how to handle "
"source type %hu.",
field_name, src_type);
ERROR("dbi plugin: Column `%s': Don't know how to handle "
"source type %hu.",
field_name, src_type);
- return
(-1)
;
+ return
-1
;
}
}
- return
(0)
;
+ return
0
;
} /* }}} int cdbi_result_get_field */
static void cdbi_database_free(cdbi_database_t *db) /* {{{ */
} /* }}} int cdbi_result_get_field */
static void cdbi_database_free(cdbi_database_t *db) /* {{{ */
@@
-221,14
+221,14
@@
static int cdbi_config_add_database_driver_option(cdbi_database_t *db, /* {{{ */
(ci->values[1].type != OCONFIG_TYPE_NUMBER))) {
WARNING("dbi plugin: The `DriverOption' config option "
"needs exactly two arguments.");
(ci->values[1].type != OCONFIG_TYPE_NUMBER))) {
WARNING("dbi plugin: The `DriverOption' config option "
"needs exactly two arguments.");
- return
(-1)
;
+ return
-1
;
}
option = realloc(db->driver_options,
sizeof(*option) * (db->driver_options_num + 1));
if (option == NULL) {
ERROR("dbi plugin: realloc failed");
}
option = realloc(db->driver_options,
sizeof(*option) * (db->driver_options_num + 1));
if (option == NULL) {
ERROR("dbi plugin: realloc failed");
- return
(-1)
;
+ return
-1
;
}
db->driver_options = option;
}
db->driver_options = option;
@@
-238,7
+238,7
@@
static int cdbi_config_add_database_driver_option(cdbi_database_t *db, /* {{{ */
option->key = strdup(ci->values[0].value.string);
if (option->key == NULL) {
ERROR("dbi plugin: strdup failed.");
option->key = strdup(ci->values[0].value.string);
if (option->key == NULL) {
ERROR("dbi plugin: strdup failed.");
- return
(-1)
;
+ return
-1
;
}
if (ci->values[1].type == OCONFIG_TYPE_STRING) {
}
if (ci->values[1].type == OCONFIG_TYPE_STRING) {
@@
-246,7
+246,7
@@
static int cdbi_config_add_database_driver_option(cdbi_database_t *db, /* {{{ */
if (option->value.string == NULL) {
ERROR("dbi plugin: strdup failed.");
sfree(option->key);
if (option->value.string == NULL) {
ERROR("dbi plugin: strdup failed.");
sfree(option->key);
- return
(-1)
;
+ return
-1
;
}
} else {
assert(ci->values[1].type == OCONFIG_TYPE_NUMBER);
}
} else {
assert(ci->values[1].type == OCONFIG_TYPE_NUMBER);
@@
-255,7
+255,7
@@
static int cdbi_config_add_database_driver_option(cdbi_database_t *db, /* {{{ */
}
db->driver_options_num++;
}
db->driver_options_num++;
- return
(0)
;
+ return
0
;
} /* }}} int cdbi_config_add_database_driver_option */
static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */
} /* }}} int cdbi_config_add_database_driver_option */
static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */
@@
-266,19
+266,19
@@
static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("dbi plugin: The `Database' block "
"needs exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("dbi plugin: The `Database' block "
"needs exactly one string argument.");
- return
(-1)
;
+ return
-1
;
}
db = calloc(1, sizeof(*db));
if (db == NULL) {
ERROR("dbi plugin: calloc failed.");
}
db = calloc(1, sizeof(*db));
if (db == NULL) {
ERROR("dbi plugin: calloc failed.");
- return
(-1)
;
+ return
-1
;
}
status = cf_util_get_string(ci, &db->name);
if (status != 0) {
sfree(db);
}
status = cf_util_get_string(ci, &db->name);
if (status != 0) {
sfree(db);
- return
(status)
;
+ return
status
;
}
/* Fill the `cdbi_database_t' structure.. */
}
/* Fill the `cdbi_database_t' structure.. */
@@
-371,10
+371,10
@@
static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */
if (status != 0) {
cdbi_database_free(db);
if (status != 0) {
cdbi_database_free(db);
- return
(-1)
;
+ return
-1
;
}
}
- return
(0)
;
+ return
0
;
} /* }}} int cdbi_config_add_database */
static int cdbi_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int cdbi_config_add_database */
static int cdbi_config(oconfig_item_t *ci) /* {{{ */
@@
-391,7
+391,7
@@
static int cdbi_config(oconfig_item_t *ci) /* {{{ */
}
} /* for (ci->children) */
}
} /* for (ci->children) */
- return
(0)
;
+ return
0
;
} /* }}} int cdbi_config */
/* }}} End of configuration handling functions */
} /* }}} int cdbi_config */
/* }}} End of configuration handling functions */
@@
-402,34
+402,34
@@
static int cdbi_init(void) /* {{{ */
int status;
if (did_init != 0)
int status;
if (did_init != 0)
- return
(0)
;
+ return
0
;
if (queries_num == 0) {
ERROR("dbi plugin: No <Query> blocks have been found. Without them, "
"this plugin can't do anything useful, so we will return an error.");
if (queries_num == 0) {
ERROR("dbi plugin: No <Query> blocks have been found. Without them, "
"this plugin can't do anything useful, so we will return an error.");
- return
(-1)
;
+ return
-1
;
}
if (databases_num == 0) {
ERROR("dbi plugin: No <Database> blocks have been found. Without them, "
"this plugin can't do anything useful, so we will return an error.");
}
if (databases_num == 0) {
ERROR("dbi plugin: No <Database> blocks have been found. Without them, "
"this plugin can't do anything useful, so we will return an error.");
- return
(-1)
;
+ return
-1
;
}
status = dbi_initialize_r(/* driverdir = */ NULL, &dbi_instance);
if (status < 0) {
ERROR("dbi plugin: cdbi_init: dbi_initialize_r failed with status %i.",
status);
}
status = dbi_initialize_r(/* driverdir = */ NULL, &dbi_instance);
if (status < 0) {
ERROR("dbi plugin: cdbi_init: dbi_initialize_r failed with status %i.",
status);
- return
(-1)
;
+ return
-1
;
} else if (status == 0) {
ERROR("dbi plugin: `dbi_initialize_r' could not load any drivers. Please "
"install at least one `DBD' or check your installation.");
} else if (status == 0) {
ERROR("dbi plugin: `dbi_initialize_r' could not load any drivers. Please "
"install at least one `DBD' or check your installation.");
- return
(-1)
;
+ return
-1
;
}
DEBUG("dbi plugin: cdbi_init: dbi_initialize_r reports %i driver%s.", status,
(status == 1) ? "" : "s");
}
DEBUG("dbi plugin: cdbi_init: dbi_initialize_r reports %i driver%s.", status,
(status == 1) ? "" : "s");
- return
(0)
;
+ return
0
;
} /* }}} int cdbi_init */
static int cdbi_read_database_query(cdbi_database_t *db, /* {{{ */
} /* }}} int cdbi_init */
static int cdbi_read_database_query(cdbi_database_t *db, /* {{{ */
@@
-619,7
+619,7
@@
static int cdbi_connect_database(cdbi_database_t *db) /* {{{ */
if (db->connection != NULL) {
status = dbi_conn_ping(db->connection);
if (status != 0) /* connection is alive */
if (db->connection != NULL) {
status = dbi_conn_ping(db->connection);
if (status != 0) /* connection is alive */
- return
(0)
;
+ return
0
;
dbi_conn_close(db->connection);
db->connection = NULL;
dbi_conn_close(db->connection);
db->connection = NULL;
@@
-635,14
+635,14
@@
static int cdbi_connect_database(cdbi_database_t *db) /* {{{ */
driver = dbi_driver_list_r(driver, dbi_instance)) {
INFO("dbi plugin: * %s", dbi_driver_get_name(driver));
}
driver = dbi_driver_list_r(driver, dbi_instance)) {
INFO("dbi plugin: * %s", dbi_driver_get_name(driver));
}
- return
(-1)
;
+ return
-1
;
}
connection = dbi_conn_open(driver);
if (connection == NULL) {
ERROR("dbi plugin: cdbi_connect_database: dbi_conn_open (%s) failed.",
db->driver);
}
connection = dbi_conn_open(driver);
if (connection == NULL) {
ERROR("dbi plugin: cdbi_connect_database: dbi_conn_open (%s) failed.",
db->driver);
- return
(-1)
;
+ return
-1
;
}
/* Set all the driver options. Because this is a very very very generic
}
/* Set all the driver options. Because this is a very very very generic
@@
-686,7
+686,7
@@
static int cdbi_connect_database(cdbi_database_t *db) /* {{{ */
}
dbi_conn_close(connection);
}
dbi_conn_close(connection);
- return
(-1)
;
+ return
-1
;
}
} /* for (i = 0; i < db->driver_options_num; i++) */
}
} /* for (i = 0; i < db->driver_options_num; i++) */
@@
-697,7
+697,7
@@
static int cdbi_connect_database(cdbi_database_t *db) /* {{{ */
"dbi_conn_connect failed: %s",
db->name, cdbi_strerror(connection, errbuf, sizeof(errbuf)));
dbi_conn_close(connection);
"dbi_conn_connect failed: %s",
db->name, cdbi_strerror(connection, errbuf, sizeof(errbuf)));
dbi_conn_close(connection);
- return
(-1)
;
+ return
-1
;
}
if (db->select_db != NULL) {
}
if (db->select_db != NULL) {
@@
-710,12
+710,12
@@
static int cdbi_connect_database(cdbi_database_t *db) /* {{{ */
db->name, db->select_db,
cdbi_strerror(connection, errbuf, sizeof(errbuf)));
dbi_conn_close(connection);
db->name, db->select_db,
cdbi_strerror(connection, errbuf, sizeof(errbuf)));
dbi_conn_close(connection);
- return
(-1)
;
+ return
-1
;
}
}
db->connection = connection;
}
}
db->connection = connection;
- return
(0)
;
+ return
0
;
} /* }}} int cdbi_connect_database */
static int cdbi_read_database(user_data_t *ud) /* {{{ */
} /* }}} int cdbi_connect_database */
static int cdbi_read_database(user_data_t *ud) /* {{{ */
@@
-728,7
+728,7
@@
static int cdbi_read_database(user_data_t *ud) /* {{{ */
status = cdbi_connect_database(db);
if (status != 0)
status = cdbi_connect_database(db);
if (status != 0)
- return
(status)
;
+ return
status
;
assert(db->connection != NULL);
db_version = dbi_conn_get_engine_version(db->connection);
assert(db->connection != NULL);
db_version = dbi_conn_get_engine_version(db->connection);
@@
-749,10
+749,10
@@
static int cdbi_read_database(user_data_t *ud) /* {{{ */
if (success == 0) {
ERROR("dbi plugin: All queries failed for database `%s'.", db->name);
if (success == 0) {
ERROR("dbi plugin: All queries failed for database `%s'.", db->name);
- return
(-1)
;
+ return
-1
;
}
}
- return
(0)
;
+ return
0
;
} /* }}} int cdbi_read_database */
static int cdbi_shutdown(void) /* {{{ */
} /* }}} int cdbi_read_database */
static int cdbi_shutdown(void) /* {{{ */
@@
-771,7
+771,7
@@
static int cdbi_shutdown(void) /* {{{ */
queries = NULL;
queries_num = 0;
queries = NULL;
queries_num = 0;
- return
(0)
;
+ return
0
;
} /* }}} int cdbi_shutdown */
void module_register(void) /* {{{ */
} /* }}} int cdbi_shutdown */
void module_register(void) /* {{{ */
@@
-780,7
+780,3
@@
void module_register(void) /* {{{ */
plugin_register_init("dbi", cdbi_init);
plugin_register_shutdown("dbi", cdbi_shutdown);
} /* }}} void module_register */
plugin_register_init("dbi", cdbi_init);
plugin_register_shutdown("dbi", cdbi_shutdown);
} /* }}} void module_register */
-
-/*
- * vim: shiftwidth=2 softtabstop=2 et fdm=marker
- */