projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #1856 from rubenk/snmp-dont-dispatch-values-with-empty-type-instance
[collectd.git]
/
src
/
oracle.c
diff --git
a/src/oracle.c
b/src/oracle.c
index
84d9ed4
..
1554830
100644
(file)
--- a/
src/oracle.c
+++ b/
src/oracle.c
@@
-46,6
+46,7
@@
**/
#include "collectd.h"
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
#include "common.h"
#include "plugin.h"
#include "configfile.h"
@@
-93,7
+94,6
@@
static void o_report_error (const char *where, /* {{{ */
char buffer[2048];
sb4 error_code;
int status;
char buffer[2048];
sb4 error_code;
int status;
- unsigned int record_number;
if (db_name == NULL)
db_name = "(none)";
if (db_name == NULL)
db_name = "(none)";
@@
-102,7
+102,7
@@
static void o_report_error (const char *where, /* {{{ */
/* An operation may cause / return multiple errors. Loop until we have
* handled all errors available (with a fail-save limit of 16). */
/* An operation may cause / return multiple errors. Loop until we have
* handled all errors available (with a fail-save limit of 16). */
- for (record_number = 1; record_number <= 16; record_number++)
+ for (
unsigned int
record_number = 1; record_number <= 16; record_number++)
{
memset (buffer, 0, sizeof (buffer));
error_code = -1;
{
memset (buffer, 0, sizeof (buffer));
error_code = -1;
@@
-144,8
+144,6
@@
static void o_report_error (const char *where, /* {{{ */
static void o_database_free (o_database_t *db) /* {{{ */
{
static void o_database_free (o_database_t *db) /* {{{ */
{
- size_t i;
-
if (db == NULL)
return;
if (db == NULL)
return;
@@
-156,7
+154,7
@@
static void o_database_free (o_database_t *db) /* {{{ */
sfree (db->queries);
if (db->q_prep_areas != NULL)
sfree (db->queries);
if (db->q_prep_areas != NULL)
- for (i = 0; i < db->queries_num; ++i)
+ 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);
udb_query_delete_preparation_area (db->q_prep_areas[i]);
free (db->q_prep_areas);
@@
-174,7
+172,7
@@
static void o_database_free (o_database_t *db) /* {{{ */
* ValuesFrom "value"
* </Result>
* </Query>
* ValuesFrom "value"
* </Result>
* </Query>
- *
+ *
* <Database "plugin_instance1">
* ConnectID "db01"
* Username "oracle"
* <Database "plugin_instance1">
* ConnectID "db01"
* Username "oracle"
@@
-188,7
+186,6
@@
static int o_config_add_database (oconfig_item_t *ci) /* {{{ */
{
o_database_t *db;
int status;
{
o_database_t *db;
int status;
- int i;
if ((ci->values_num != 1)
|| (ci->values[0].type != OCONFIG_TYPE_STRING))
if ((ci->values_num != 1)
|| (ci->values[0].type != OCONFIG_TYPE_STRING))
@@
-198,13
+195,12
@@
static int o_config_add_database (oconfig_item_t *ci) /* {{{ */
return (-1);
}
return (-1);
}
- db =
malloc (
sizeof (*db));
+ db =
calloc (1,
sizeof (*db));
if (db == NULL)
{
if (db == NULL)
{
- ERROR ("oracle plugin:
m
alloc failed.");
+ ERROR ("oracle plugin:
c
alloc failed.");
return (-1);
}
return (-1);
}
- memset (db, 0, sizeof (*db));
db->name = NULL;
db->host = NULL;
db->connect_id = NULL;
db->name = NULL;
db->host = NULL;
db->connect_id = NULL;
@@
-219,7
+215,7
@@
static int o_config_add_database (oconfig_item_t *ci) /* {{{ */
}
/* Fill the `o_database_t' structure.. */
}
/* Fill the `o_database_t' structure.. */
- for (i = 0; i < ci->children_num; i++)
+ for (i
nt i
= 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
{
oconfig_item_t *child = ci->children + i;
@@
-273,12
+269,12
@@
static int o_config_add_database (oconfig_item_t *ci) /* {{{ */
if (db->q_prep_areas == NULL)
{
if (db->q_prep_areas == NULL)
{
- WARNING ("oracle plugin:
m
alloc failed");
+ WARNING ("oracle plugin:
c
alloc failed");
status = -1;
break;
}
status = -1;
break;
}
- for (i = 0; i < db->queries_num; ++i)
+ for (i
nt i
= 0; i < db->queries_num; ++i)
{
db->q_prep_areas[i]
= udb_query_allocate_preparation_area (db->queries[i]);
{
db->q_prep_areas[i]
= udb_query_allocate_preparation_area (db->queries[i]);
@@
-300,7
+296,7
@@
static int o_config_add_database (oconfig_item_t *ci) /* {{{ */
{
o_database_t **temp;
{
o_database_t **temp;
- temp =
(o_database_t **)
realloc (databases,
+ temp = realloc (databases,
sizeof (*databases) * (databases_num + 1));
if (temp == NULL)
{
sizeof (*databases) * (databases_num + 1));
if (temp == NULL)
{
@@
-326,9
+322,7
@@
static int o_config_add_database (oconfig_item_t *ci) /* {{{ */
static int o_config (oconfig_item_t *ci) /* {{{ */
{
static int o_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
if (strcasecmp ("Query", child->key) == 0)
{
oconfig_item_t *child = ci->children + i;
if (strcasecmp ("Query", child->key) == 0)
@@
-400,7
+394,6
@@
static int o_read_database_query (o_database_t *db, /* {{{ */
OCIDefine **oci_defines;
int status;
OCIDefine **oci_defines;
int status;
- size_t i;
oci_statement = udb_query_get_user_data (q);
oci_statement = udb_query_get_user_data (q);
@@
-463,7
+456,7
@@
static int o_read_database_query (o_database_t *db, /* {{{ */
{
ub4 param_counter = 0;
status = OCIAttrGet (oci_statement, OCI_HTYPE_STMT, /* {{{ */
{
ub4 param_counter = 0;
status = OCIAttrGet (oci_statement, OCI_HTYPE_STMT, /* {{{ */
- ¶m_counter, /* size pointer = */ NULL,
+ ¶m_counter, /* size pointer = */ NULL,
OCI_ATTR_PARAM_COUNT, oci_error);
if (status != OCI_SUCCESS)
{
OCI_ATTR_PARAM_COUNT, oci_error);
if (status != OCI_SUCCESS)
{
@@
-476,7
+469,7
@@
static int o_read_database_query (o_database_t *db, /* {{{ */
} while (0); /* }}} */
/* Allocate the following buffers:
} while (0); /* }}} */
/* Allocate the following buffers:
- *
+ *
* +---------------+-----------------------------------+
* ! Name ! Size !
* +---------------+-----------------------------------+
* +---------------+-----------------------------------+
* ! Name ! Size !
* +---------------+-----------------------------------+
@@
-502,13
+495,12
@@
static int o_read_database_query (o_database_t *db, /* {{{ */
#define ALLOC_OR_FAIL(ptr, ptr_size) \
do { \
size_t alloc_size = (size_t) ((ptr_size)); \
#define ALLOC_OR_FAIL(ptr, ptr_size) \
do { \
size_t alloc_size = (size_t) ((ptr_size)); \
- (ptr) =
malloc (
alloc_size); \
+ (ptr) =
calloc (1,
alloc_size); \
if ((ptr) == NULL) { \
FREE_ALL; \
if ((ptr) == NULL) { \
FREE_ALL; \
- ERROR ("oracle plugin: o_read_database_query:
m
alloc failed."); \
+ ERROR ("oracle plugin: o_read_database_query:
c
alloc failed."); \
return (-1); \
} \
return (-1); \
} \
- memset ((ptr), 0, alloc_size); \
} while (0)
/* Initialize everything to NULL so the above works. */
} while (0)
/* Initialize everything to NULL so the above works. */
@@
-519,13
+511,13
@@
static int o_read_database_query (o_database_t *db, /* {{{ */
ALLOC_OR_FAIL (column_names, column_num * sizeof (char *));
ALLOC_OR_FAIL (column_names[0], column_num * DATA_MAX_NAME_LEN
* sizeof (char));
ALLOC_OR_FAIL (column_names, column_num * sizeof (char *));
ALLOC_OR_FAIL (column_names[0], column_num * DATA_MAX_NAME_LEN
* sizeof (char));
- for (i = 1; i < column_num; i++)
+ for (
size_t
i = 1; i < column_num; i++)
column_names[i] = column_names[i - 1] + DATA_MAX_NAME_LEN;
ALLOC_OR_FAIL (column_values, column_num * sizeof (char *));
ALLOC_OR_FAIL (column_values[0], column_num * DATA_MAX_NAME_LEN
* sizeof (char));
column_names[i] = column_names[i - 1] + DATA_MAX_NAME_LEN;
ALLOC_OR_FAIL (column_values, column_num * sizeof (char *));
ALLOC_OR_FAIL (column_values[0], column_num * DATA_MAX_NAME_LEN
* sizeof (char));
- for (i = 1; i < column_num; i++)
+ for (
size_t
i = 1; i < column_num; i++)
column_values[i] = column_values[i - 1] + DATA_MAX_NAME_LEN;
ALLOC_OR_FAIL (oci_defines, column_num * sizeof (OCIDefine *));
column_values[i] = column_values[i - 1] + DATA_MAX_NAME_LEN;
ALLOC_OR_FAIL (oci_defines, column_num * sizeof (OCIDefine *));
@@
-533,7
+525,7
@@
static int o_read_database_query (o_database_t *db, /* {{{ */
/* ``Define'' the returned data, i. e. bind the columns to the buffers
* allocated above. */
/* ``Define'' the returned data, i. e. bind the columns to the buffers
* allocated above. */
- for (i = 0; i < column_num; i++) /* {{{ */
+ for (
size_t
i = 0; i < column_num; i++) /* {{{ */
{
char *column_name;
ub4 column_name_length;
{
char *column_name;
ub4 column_name_length;
@@
-644,7
+636,6
@@
static int o_read_database_query (o_database_t *db, /* {{{ */
static int o_read_database (o_database_t *db) /* {{{ */
{
static int o_read_database (o_database_t *db) /* {{{ */
{
- size_t i;
int status;
if (db->oci_service_context != NULL)
int status;
if (db->oci_service_context != NULL)
@@
-653,7
+644,7
@@
static int o_read_database (o_database_t *db) /* {{{ */
ub4 connection_status;
server_handle = NULL;
ub4 connection_status;
server_handle = NULL;
- status = OCIAttrGet ((void *) db->oci_service_context, OCI_HTYPE_SVCCTX,
+ status = OCIAttrGet ((void *) db->oci_service_context, OCI_HTYPE_SVCCTX,
(void *) &server_handle, /* size pointer = */ NULL,
OCI_ATTR_SERVER, oci_error);
if (status != OCI_SUCCESS)
(void *) &server_handle, /* size pointer = */ NULL,
OCI_ATTR_SERVER, oci_error);
if (status != OCI_SUCCESS)
@@
-719,7
+710,7
@@
static int o_read_database (o_database_t *db) /* {{{ */
DEBUG ("oracle plugin: o_read_database: db->connect_id = %s; db->oci_service_context = %p;",
db->connect_id, db->oci_service_context);
DEBUG ("oracle plugin: o_read_database: db->connect_id = %s; db->oci_service_context = %p;",
db->connect_id, db->oci_service_context);
- for (i = 0; i < db->queries_num; i++)
+ for (
size_t
i = 0; i < db->queries_num; i++)
o_read_database_query (db, db->queries[i], db->q_prep_areas[i]);
return (0);
o_read_database_query (db, db->queries[i], db->q_prep_areas[i]);
return (0);
@@
-745,7
+736,7
@@
static int o_shutdown (void) /* {{{ */
OCIHandleFree (databases[i]->oci_service_context, OCI_HTYPE_SVCCTX);
databases[i]->oci_service_context = NULL;
}
OCIHandleFree (databases[i]->oci_service_context, OCI_HTYPE_SVCCTX);
databases[i]->oci_service_context = NULL;
}
-
+
for (i = 0; i < queries_num; i++)
{
OCIStmt *oci_statement;
for (i = 0; i < queries_num; i++)
{
OCIStmt *oci_statement;
@@
-757,7
+748,7
@@
static int o_shutdown (void) /* {{{ */
udb_query_set_user_data (queries[i], NULL);
}
}
udb_query_set_user_data (queries[i], NULL);
}
}
-
+
OCIHandleFree (oci_env, OCI_HTYPE_ENV);
oci_env = NULL;
OCIHandleFree (oci_env, OCI_HTYPE_ENV);
oci_env = NULL;