projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
daemon/common.[ch]: add set_sock_opts() function
[collectd.git]
/
src
/
table.c
diff --git
a/src/table.c
b/src/table.c
index
98858d2
..
ba65f41
100644
(file)
--- a/
src/table.c
+++ b/
src/table.c
@@
-29,6
+29,7
@@
*/
#include "collectd.h"
*/
#include "collectd.h"
+
#include "common.h"
#include "configfile.h"
#include "common.h"
#include "configfile.h"
@@
-42,12
+43,12
@@
*/
typedef struct {
*/
typedef struct {
- char *type;
- char *instance_prefix;
-
int
*instances;
- size_t instances_num;
-
int
*values;
- size_t values_num;
+ char
*type;
+ char
*instance_prefix;
+
size_t
*instances;
+ size_t
instances_num;
+
size_t
*values;
+ size_t
values_num;
const data_set_t *ds;
} tbl_result_t;
const data_set_t *ds;
} tbl_result_t;
@@
-105,13
+106,11
@@
static void tbl_setup (tbl_t *tbl, char *file)
static void tbl_clear (tbl_t *tbl)
{
static void tbl_clear (tbl_t *tbl)
{
- size_t i;
-
sfree (tbl->file);
sfree (tbl->sep);
sfree (tbl->instance);
sfree (tbl->file);
sfree (tbl->sep);
sfree (tbl->instance);
- for (i = 0; i < tbl->results_num; ++i)
+ for (
size_t
i = 0; i < tbl->results_num; ++i)
tbl_result_clear (tbl->results + i);
sfree (tbl->results);
tbl->results_num = 0;
tbl_result_clear (tbl->results + i);
sfree (tbl->results);
tbl->results_num = 0;
@@
-139,38
+138,39
@@
static int tbl_config_set_s (char *name, char **var, oconfig_item_t *ci)
return 0;
} /* tbl_config_set_separator */
return 0;
} /* tbl_config_set_separator */
-static int tbl_config_append_array_i (char *name,
in
t **var, size_t *len,
+static int tbl_config_append_array_i (char *name,
size_
t **var, size_t *len,
oconfig_item_t *ci)
{
oconfig_item_t *ci)
{
- int *tmp;
-
- size_t i;
+ size_t *tmp;
+ size_t num;
if (1 > ci->values_num) {
log_err ("\"%s\" expects at least one argument.", name);
return 1;
}
if (1 > ci->values_num) {
log_err ("\"%s\" expects at least one argument.", name);
return 1;
}
- for (i = 0; i < ci->values_num; ++i) {
+ num = (size_t) ci->values_num;
+ for (size_t i = 0; i < num; ++i) {
if (OCONFIG_TYPE_NUMBER != ci->values[i].type) {
log_err ("\"%s\" expects numerical arguments only.", name);
return 1;
}
}
if (OCONFIG_TYPE_NUMBER != ci->values[i].type) {
log_err ("\"%s\" expects numerical arguments only.", name);
return 1;
}
}
- *len += ci->values_num;
- tmp = (int *)realloc (*var, *len * sizeof (**var));
+ tmp = realloc (*var, ((*len) + num) * sizeof (**var));
if (NULL == tmp) {
char errbuf[1024];
log_err ("realloc failed: %s.",
sstrerror (errno, errbuf, sizeof (errbuf)));
return -1;
}
if (NULL == tmp) {
char errbuf[1024];
log_err ("realloc failed: %s.",
sstrerror (errno, errbuf, sizeof (errbuf)));
return -1;
}
-
*var = tmp;
*var = tmp;
- for (i = *len - ci->values_num; i < *len; ++i)
- (*var)[i] = (int)ci->values[i].value.number;
+ for (size_t i = 0; i < num; ++i) {
+ (*var)[*len] = (size_t) ci->values[i].value.number;
+ (*len)++;
+ }
+
return 0;
} /* tbl_config_append_array_s */
return 0;
} /* tbl_config_append_array_s */
@@
-179,16
+179,15
@@
static int tbl_config_result (tbl_t *tbl, oconfig_item_t *ci)
tbl_result_t *res;
int status = 0;
tbl_result_t *res;
int status = 0;
- size_t i;
if (0 != ci->values_num) {
log_err ("<Result> does not expect any arguments.");
return 1;
}
if (0 != ci->values_num) {
log_err ("<Result> does not expect any arguments.");
return 1;
}
- res =
(tbl_result_t *)
realloc (tbl->results,
+ res = realloc (tbl->results,
(tbl->results_num + 1) * sizeof (*tbl->results));
(tbl->results_num + 1) * sizeof (*tbl->results));
- if (
NULL == tbl
) {
+ if (
res == NULL
) {
char errbuf[1024];
log_err ("realloc failed: %s.",
sstrerror (errno, errbuf, sizeof (errbuf)));
char errbuf[1024];
log_err ("realloc failed: %s.",
sstrerror (errno, errbuf, sizeof (errbuf)));
@@
-201,7
+200,7
@@
static int tbl_config_result (tbl_t *tbl, oconfig_item_t *ci)
res = tbl->results + tbl->results_num - 1;
tbl_result_setup (res);
res = tbl->results + tbl->results_num - 1;
tbl_result_setup (res);
- for (i = 0; i < ci->children_num; ++i) {
+ for (i
nt i
= 0; i < ci->children_num; ++i) {
oconfig_item_t *c = ci->children + i;
if (0 == strcasecmp (c->key, "Type"))
oconfig_item_t *c = ci->children + i;
if (0 == strcasecmp (c->key, "Type"))
@@
-244,7
+243,6
@@
static int tbl_config_table (oconfig_item_t *ci)
tbl_t *tbl;
int status = 0;
tbl_t *tbl;
int status = 0;
- size_t i;
if ((1 != ci->values_num)
|| (OCONFIG_TYPE_STRING != ci->values[0].type)) {
if ((1 != ci->values_num)
|| (OCONFIG_TYPE_STRING != ci->values[0].type)) {
@@
-252,7
+250,7
@@
static int tbl_config_table (oconfig_item_t *ci)
return 1;
}
return 1;
}
- tbl =
(tbl_t *)
realloc (tables, (tables_num + 1) * sizeof (*tables));
+ tbl = realloc (tables, (tables_num + 1) * sizeof (*tables));
if (NULL == tbl) {
char errbuf[1024];
log_err ("realloc failed: %s.",
if (NULL == tbl) {
char errbuf[1024];
log_err ("realloc failed: %s.",
@@
-266,7
+264,7
@@
static int tbl_config_table (oconfig_item_t *ci)
tbl = tables + tables_num - 1;
tbl_setup (tbl, ci->values[0].value.string);
tbl = tables + tables_num - 1;
tbl_setup (tbl, ci->values[0].value.string);
- for (
i = 0; i < ci->children_num
; ++i) {
+ for (
size_t i = 0; i < ((size_t) ci->children_num)
; ++i) {
oconfig_item_t *c = ci->children + i;
if (0 == strcasecmp (c->key, "Separator"))
oconfig_item_t *c = ci->children + i;
if (0 == strcasecmp (c->key, "Separator"))
@@
-304,15
+302,14
@@
static int tbl_config_table (oconfig_item_t *ci)
return status;
}
return status;
}
- for (i = 0; i < tbl->results_num; ++i) {
+ for (
size_t
i = 0; i < tbl->results_num; ++i) {
tbl_result_t *res = tbl->results + i;
tbl_result_t *res = tbl->results + i;
- size_t j;
- for (j = 0; j < res->instances_num; ++j)
+ for (
size_t
j = 0; j < res->instances_num; ++j)
if (res->instances[j] > tbl->max_colnum)
tbl->max_colnum = res->instances[j];
if (res->instances[j] > tbl->max_colnum)
tbl->max_colnum = res->instances[j];
- for (j = 0; j < res->values_num; ++j)
+ for (
size_t
j = 0; j < res->values_num; ++j)
if (res->values[j] > tbl->max_colnum)
tbl->max_colnum = res->values[j];
}
if (res->values[j] > tbl->max_colnum)
tbl->max_colnum = res->values[j];
}
@@
-321,9
+318,7
@@
static int tbl_config_table (oconfig_item_t *ci)
static int tbl_config (oconfig_item_t *ci)
{
static int tbl_config (oconfig_item_t *ci)
{
- size_t i;
-
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *c = ci->children + i;
if (0 == strcasecmp (c->key, "Table"))
oconfig_item_t *c = ci->children + i;
if (0 == strcasecmp (c->key, "Table"))
@@
-340,9
+335,7
@@
static int tbl_config (oconfig_item_t *ci)
static int tbl_prepare (tbl_t *tbl)
{
static int tbl_prepare (tbl_t *tbl)
{
- size_t i;
-
- for (i = 0; i < tbl->results_num; ++i) {
+ for (size_t i = 0; i < tbl->results_num; ++i) {
tbl_result_t *res = tbl->results + i;
res->ds = plugin_get_ds (res->type);
tbl_result_t *res = tbl->results + i;
res->ds = plugin_get_ds (res->type);
@@
-365,9
+358,7
@@
static int tbl_prepare (tbl_t *tbl)
static int tbl_finish (tbl_t *tbl)
{
static int tbl_finish (tbl_t *tbl)
{
- size_t i;
-
- for (i = 0; i < tbl->results_num; ++i)
+ for (size_t i = 0; i < tbl->results_num; ++i)
tbl->results[i].ds = NULL;
return 0;
} /* tbl_finish */
tbl->results[i].ds = NULL;
return 0;
} /* tbl_finish */
@@
-378,12
+369,10
@@
static int tbl_result_dispatch (tbl_t *tbl, tbl_result_t *res,
value_list_t vl = VALUE_LIST_INIT;
value_t values[res->values_num];
value_list_t vl = VALUE_LIST_INIT;
value_t values[res->values_num];
- size_t i;
-
assert (NULL != res->ds);
assert (res->values_num == res->ds->ds_num);
assert (NULL != res->ds);
assert (res->values_num == res->ds->ds_num);
- for (i = 0; i < res->values_num; ++i) {
+ for (
size_t
i = 0; i < res->values_num; ++i) {
char *value;
assert (res->values[i] < fields_num);
char *value;
assert (res->values[i] < fields_num);
@@
-410,7
+399,7
@@
static int tbl_result_dispatch (tbl_t *tbl, tbl_result_t *res,
char *instances[res->instances_num];
char instances_str[DATA_MAX_NAME_LEN];
char *instances[res->instances_num];
char instances_str[DATA_MAX_NAME_LEN];
- for (i = 0; i < res->instances_num; ++i) {
+ for (
size_t
i = 0; i < res->instances_num; ++i) {
assert (res->instances[i] < fields_num);
instances[i] = fields[res->instances[i]];
}
assert (res->instances[i] < fields_num);
instances[i] = fields[res->instances[i]];
}
@@
-442,9
+431,8
@@
static int tbl_parse_line (tbl_t *tbl, char *line, size_t len)
char *fields[tbl->max_colnum + 1];
char *ptr, *saveptr;
char *fields[tbl->max_colnum + 1];
char *ptr, *saveptr;
- size_t i;
+ size_t i
= 0
;
- i = 0;
ptr = line;
saveptr = NULL;
while (NULL != (fields[i] = strtok_r (ptr, tbl->sep, &saveptr))) {
ptr = line;
saveptr = NULL;
while (NULL != (fields[i] = strtok_r (ptr, tbl->sep, &saveptr))) {
@@
-456,7
+444,7
@@
static int tbl_parse_line (tbl_t *tbl, char *line, size_t len)
}
if (i <= tbl->max_colnum) {
}
if (i <= tbl->max_colnum) {
- log_
err
("Not enough columns in line "
+ log_
warn
("Not enough columns in line "
"(expected at least %zu, got %zu).",
tbl->max_colnum + 1, i);
return -1;
"(expected at least %zu, got %zu).",
tbl->max_colnum + 1, i);
return -1;
@@
-488,11
+476,11
@@
static int tbl_read_table (tbl_t *tbl)
while (NULL != fgets (buf, sizeof (buf), fh)) {
if ('\0' != buf[sizeof (buf) - 1]) {
buf[sizeof (buf) - 1] = '\0';
while (NULL != fgets (buf, sizeof (buf), fh)) {
if ('\0' != buf[sizeof (buf) - 1]) {
buf[sizeof (buf) - 1] = '\0';
- log_
err
("Table %s: Truncated line: %s", tbl->file, buf);
+ log_
warn
("Table %s: Truncated line: %s", tbl->file, buf);
}
if (0 != tbl_parse_line (tbl, buf, sizeof (buf))) {
}
if (0 != tbl_parse_line (tbl, buf, sizeof (buf))) {
- log_
err
("Table %s: Failed to parse line: %s", tbl->file, buf);
+ log_
warn
("Table %s: Failed to parse line: %s", tbl->file, buf);
continue;
}
}
continue;
}
}
@@
-516,12
+504,11
@@
static int tbl_read_table (tbl_t *tbl)
static int tbl_read (void)
{
int status = -1;
static int tbl_read (void)
{
int status = -1;
- size_t i;
if (0 == tables_num)
return 0;
if (0 == tables_num)
return 0;
- for (i = 0; i < tables_num; ++i) {
+ for (
size_t
i = 0; i < tables_num; ++i) {
tbl_t *tbl = tables + i;
if (0 != tbl_prepare (tbl)) {
tbl_t *tbl = tables + i;
if (0 != tbl_prepare (tbl)) {
@@
-539,9
+526,7
@@
static int tbl_read (void)
static int tbl_shutdown (void)
{
static int tbl_shutdown (void)
{
- size_t i;
-
- for (i = 0; i < tables_num; ++i)
+ for (size_t i = 0; i < tables_num; ++i)
tbl_clear (&tables[i]);
sfree (tables);
return 0;
tbl_clear (&tables[i]);
sfree (tables);
return 0;