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 #1842 from rubenk/declare-loop-variable-in-for-loop-controlling...
[collectd.git]
/
src
/
threshold.c
diff --git
a/src/threshold.c
b/src/threshold.c
index
b753d37
..
1d9bcf9
100644
(file)
--- a/
src/threshold.c
+++ b/
src/threshold.c
@@
-24,15
+24,13
@@
**/
#include "collectd.h"
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_avltree.h"
#include "utils_cache.h"
#include "utils_threshold.h"
#include "common.h"
#include "plugin.h"
#include "utils_avltree.h"
#include "utils_cache.h"
#include "utils_threshold.h"
-#include <assert.h>
-#include <pthread.h>
-
/*
* Threshold management
* ====================
/*
* Threshold management
* ====================
@@
-70,7
+68,7
@@
static int ut_threshold_add (const threshold_t *th)
return (-1);
}
return (-1);
}
- th_copy =
(threshold_t *) malloc (sizeof (threshold_t
));
+ th_copy =
malloc (sizeof (*th_copy
));
if (th_copy == NULL)
{
sfree (name_copy);
if (th_copy == NULL)
{
sfree (name_copy);
@@
-78,7
+76,6
@@
static int ut_threshold_add (const threshold_t *th)
return (-1);
}
memcpy (th_copy, th, sizeof (threshold_t));
return (-1);
}
memcpy (th_copy, th, sizeof (threshold_t));
- th_ptr = NULL;
DEBUG ("ut_threshold_add: Adding entry `%s'", name);
DEBUG ("ut_threshold_add: Adding entry `%s'", name);
@@
-219,7
+216,6
@@
static int ut_config_type_hysteresis (threshold_t *th, oconfig_item_t *ci)
static int ut_config_type (const threshold_t *th_orig, oconfig_item_t *ci)
{
static int ut_config_type (const threshold_t *th_orig, oconfig_item_t *ci)
{
- int i;
threshold_t th;
int status = 0;
threshold_t th;
int status = 0;
@@
-248,7
+244,7
@@
static int ut_config_type (const threshold_t *th_orig, oconfig_item_t *ci)
th.hysteresis = 0;
th.flags = UT_FLAG_INTERESTING; /* interesting by default */
th.hysteresis = 0;
th.flags = UT_FLAG_INTERESTING; /* interesting by default */
- for (i = 0; i < ci->children_num; i++)
+ for (i
nt i
= 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
{
oconfig_item_t *option = ci->children + i;
@@
-313,7
+309,6
@@
static int ut_config_plugin_instance (threshold_t *th, oconfig_item_t *ci)
static int ut_config_plugin (const threshold_t *th_orig, oconfig_item_t *ci)
{
static int ut_config_plugin (const threshold_t *th_orig, oconfig_item_t *ci)
{
- int i;
threshold_t th;
int status = 0;
threshold_t th;
int status = 0;
@@
-335,7
+330,7
@@
static int ut_config_plugin (const threshold_t *th_orig, oconfig_item_t *ci)
memcpy (&th, th_orig, sizeof (th));
sstrncpy (th.plugin, ci->values[0].value.string, sizeof (th.plugin));
memcpy (&th, th_orig, sizeof (th));
sstrncpy (th.plugin, ci->values[0].value.string, sizeof (th.plugin));
- for (i = 0; i < ci->children_num; i++)
+ for (i
nt i
= 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
{
oconfig_item_t *option = ci->children + i;
@@
-359,7
+354,6
@@
static int ut_config_plugin (const threshold_t *th_orig, oconfig_item_t *ci)
static int ut_config_host (const threshold_t *th_orig, oconfig_item_t *ci)
{
static int ut_config_host (const threshold_t *th_orig, oconfig_item_t *ci)
{
- int i;
threshold_t th;
int status = 0;
threshold_t th;
int status = 0;
@@
-381,7
+375,7
@@
static int ut_config_host (const threshold_t *th_orig, oconfig_item_t *ci)
memcpy (&th, th_orig, sizeof (th));
sstrncpy (th.host, ci->values[0].value.string, sizeof (th.host));
memcpy (&th, th_orig, sizeof (th));
sstrncpy (th.host, ci->values[0].value.string, sizeof (th.host));
- for (i = 0; i < ci->children_num; i++)
+ for (i
nt i
= 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
{
oconfig_item_t *option = ci->children + i;
@@
-553,10
+547,9
@@
static int ut_report_state (const data_set_t *ds,
{
gauge_t value;
gauge_t sum;
{
gauge_t value;
gauge_t sum;
- size_t i;
sum = 0.0;
sum = 0.0;
- for (i = 0; i < vl->values_len; i++)
+ for (
size_t
i = 0; i < vl->values_len; i++)
{
if (isnan (values[i]))
continue;
{
if (isnan (values[i]))
continue;
@@
-701,7
+694,6
@@
static int ut_check_one_threshold (const data_set_t *ds,
{ /* {{{ */
int ret = -1;
int ds_index = -1;
{ /* {{{ */
int ret = -1;
int ds_index = -1;
- size_t i;
gauge_t values_copy[ds->ds_num];
memcpy (values_copy, values, sizeof (values_copy));
gauge_t values_copy[ds->ds_num];
memcpy (values_copy, values, sizeof (values_copy));
@@
-720,7
+712,7
@@
static int ut_check_one_threshold (const data_set_t *ds,
}
/* Prepare `sum' and `num'. */
}
/* Prepare `sum' and `num'. */
- for (i = 0; i < ds->ds_num; i++)
+ for (
size_t
i = 0; i < ds->ds_num; i++)
if (!isnan (values[i]))
{
num++;
if (!isnan (values[i]))
{
num++;
@@
-730,17
+722,17
@@
static int ut_check_one_threshold (const data_set_t *ds,
if ((num == 0) /* All data sources are undefined. */
|| (sum == 0.0)) /* Sum is zero, cannot calculate percentage. */
{
if ((num == 0) /* All data sources are undefined. */
|| (sum == 0.0)) /* Sum is zero, cannot calculate percentage. */
{
- for (i = 0; i < ds->ds_num; i++)
+ for (
size_t
i = 0; i < ds->ds_num; i++)
values_copy[i] = NAN;
}
else /* We can actually calculate the percentage. */
{
values_copy[i] = NAN;
}
else /* We can actually calculate the percentage. */
{
- for (i = 0; i < ds->ds_num; i++)
+ for (
size_t
i = 0; i < ds->ds_num; i++)
values_copy[i] = 100.0 * values[i] / sum;
}
} /* if (UT_FLAG_PERCENTAGE) */
values_copy[i] = 100.0 * values[i] / sum;
}
} /* if (UT_FLAG_PERCENTAGE) */
- for (i = 0; i < ds->ds_num; i++)
+ for (
size_t
i = 0; i < ds->ds_num; i++)
{
int status;
{
int status;
@@
-868,17
+860,14
@@
static int ut_missing (const value_list_t *vl,
return (0);
} /* }}} int ut_missing */
return (0);
} /* }}} int ut_missing */
-int ut_config (oconfig_item_t *ci)
+
static
int ut_config (oconfig_item_t *ci)
{ /* {{{ */
{ /* {{{ */
- int i;
int status = 0;
int old_size = c_avl_size (threshold_tree);
int status = 0;
int old_size = c_avl_size (threshold_tree);
- threshold_t th;
-
if (threshold_tree == NULL)
{
if (threshold_tree == NULL)
{
- threshold_tree = c_avl_create ((
void *
) strcmp);
+ threshold_tree = c_avl_create ((
int (*) (const void *, const void *)
) strcmp);
if (threshold_tree == NULL)
{
ERROR ("ut_config: c_avl_create failed.");
if (threshold_tree == NULL)
{
ERROR ("ut_config: c_avl_create failed.");
@@
-886,17
+875,15
@@
int ut_config (oconfig_item_t *ci)
}
}
}
}
- memset (&th, '\0', sizeof (th));
- th.warning_min = NAN;
- th.warning_max = NAN;
- th.failure_min = NAN;
- th.failure_max = NAN;
-
- th.hits = 0;
- th.hysteresis = 0;
- th.flags = UT_FLAG_INTERESTING; /* interesting by default */
+ threshold_t th = {
+ .warning_min = NAN,
+ .warning_max = NAN,
+ .failure_min = NAN,
+ .failure_max = NAN,
+ .flags = UT_FLAG_INTERESTING /* interesting by default */
+ };
- for (i = 0; i < ci->children_num; i++)
+ for (i
nt i
= 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
{
oconfig_item_t *option = ci->children + i;