X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fdaemon%2Futils_threshold.c;h=8c03341148af5931269f8d088cad132be04affb4;hp=4a8df89d69e70c147e1fa8820c7884d1931b427c;hb=1159cb5d383c55a80a0db100b8f7aadcf44740a5;hpb=b81104a423234c04f0eb4ace0ec5e93a363c917a diff --git a/src/daemon/utils_threshold.c b/src/daemon/utils_threshold.c index 4a8df89d..8c033411 100644 --- a/src/daemon/utils_threshold.c +++ b/src/daemon/utils_threshold.c @@ -25,6 +25,7 @@ **/ #include "collectd.h" + #include "common.h" #include "utils_avltree.h" #include "utils_threshold.h" @@ -34,7 +35,7 @@ /* * Exported symbols * {{{ */ -c_avl_tree_t *threshold_tree = NULL; +c_avl_tree_t *threshold_tree = NULL; pthread_mutex_t threshold_lock = PTHREAD_MUTEX_INITIALIZER; /* }}} */ @@ -45,23 +46,21 @@ pthread_mutex_t threshold_lock = PTHREAD_MUTEX_INITIALIZER; * matching a value_list_t, see "threshold_search" below. Returns NULL if the * specified threshold doesn't exist. */ -threshold_t *threshold_get (const char *hostname, - const char *plugin, const char *plugin_instance, - const char *type, const char *type_instance) -{ /* {{{ */ +threshold_t *threshold_get(const char *hostname, const char *plugin, + const char *plugin_instance, const char *type, + const char *type_instance) { /* {{{ */ char name[6 * DATA_MAX_NAME_LEN]; threshold_t *th = NULL; - format_name (name, sizeof (name), - (hostname == NULL) ? "" : hostname, - (plugin == NULL) ? "" : plugin, plugin_instance, - (type == NULL) ? "" : type, type_instance); - name[sizeof (name) - 1] = '\0'; + format_name(name, sizeof(name), (hostname == NULL) ? "" : hostname, + (plugin == NULL) ? "" : plugin, plugin_instance, + (type == NULL) ? "" : type, type_instance); + name[sizeof(name) - 1] = '\0'; - if (c_avl_get (threshold_tree, name, (void *) &th) == 0) - return (th); + if (c_avl_get(threshold_tree, name, (void *)&th) == 0) + return th; else - return (NULL); + return NULL; } /* }}} threshold_t *threshold_get */ /* @@ -72,72 +71,65 @@ threshold_t *threshold_get (const char *hostname, * found. * XXX: This is likely the least efficient function in collectd. */ -threshold_t *threshold_search (const value_list_t *vl) -{ /* {{{ */ +threshold_t *threshold_search(const value_list_t *vl) { /* {{{ */ threshold_t *th; - if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance, - vl->type, vl->type_instance)) != NULL) - return (th); - else if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance, - vl->type, NULL)) != NULL) - return (th); - else if ((th = threshold_get (vl->host, vl->plugin, NULL, - vl->type, vl->type_instance)) != NULL) - return (th); - else if ((th = threshold_get (vl->host, vl->plugin, NULL, - vl->type, NULL)) != NULL) - return (th); - else if ((th = threshold_get (vl->host, "", NULL, - vl->type, vl->type_instance)) != NULL) - return (th); - else if ((th = threshold_get (vl->host, "", NULL, - vl->type, NULL)) != NULL) - return (th); - else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance, - vl->type, vl->type_instance)) != NULL) - return (th); - else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance, - vl->type, NULL)) != NULL) - return (th); - else if ((th = threshold_get ("", vl->plugin, NULL, - vl->type, vl->type_instance)) != NULL) - return (th); - else if ((th = threshold_get ("", vl->plugin, NULL, - vl->type, NULL)) != NULL) - return (th); - else if ((th = threshold_get ("", "", NULL, - vl->type, vl->type_instance)) != NULL) - return (th); - else if ((th = threshold_get ("", "", NULL, - vl->type, NULL)) != NULL) - return (th); - - return (NULL); + if ((th = threshold_get(vl->host, vl->plugin, vl->plugin_instance, vl->type, + vl->type_instance)) != NULL) + return th; + else if ((th = threshold_get(vl->host, vl->plugin, vl->plugin_instance, + vl->type, NULL)) != NULL) + return th; + else if ((th = threshold_get(vl->host, vl->plugin, NULL, vl->type, + vl->type_instance)) != NULL) + return th; + else if ((th = threshold_get(vl->host, vl->plugin, NULL, vl->type, NULL)) != + NULL) + return th; + else if ((th = threshold_get(vl->host, "", NULL, vl->type, + vl->type_instance)) != NULL) + return th; + else if ((th = threshold_get(vl->host, "", NULL, vl->type, NULL)) != NULL) + return th; + else if ((th = threshold_get("", vl->plugin, vl->plugin_instance, vl->type, + vl->type_instance)) != NULL) + return th; + else if ((th = threshold_get("", vl->plugin, vl->plugin_instance, vl->type, + NULL)) != NULL) + return th; + else if ((th = threshold_get("", vl->plugin, NULL, vl->type, + vl->type_instance)) != NULL) + return th; + else if ((th = threshold_get("", vl->plugin, NULL, vl->type, NULL)) != NULL) + return th; + else if ((th = threshold_get("", "", NULL, vl->type, vl->type_instance)) != + NULL) + return th; + else if ((th = threshold_get("", "", NULL, vl->type, NULL)) != NULL) + return th; + + return NULL; } /* }}} threshold_t *threshold_search */ -int ut_search_threshold (const value_list_t *vl, /* {{{ */ - threshold_t *ret_threshold) -{ +int ut_search_threshold(const value_list_t *vl, /* {{{ */ + threshold_t *ret_threshold) { threshold_t *t; if (vl == NULL) - return (EINVAL); + return EINVAL; - /* Is this lock really necessary? */ - pthread_mutex_lock (&threshold_lock); - t = threshold_search (vl); + /* Is this lock really necessary? */ + pthread_mutex_lock(&threshold_lock); + t = threshold_search(vl); if (t == NULL) { - pthread_mutex_unlock (&threshold_lock); - return (ENOENT); - } + pthread_mutex_unlock(&threshold_lock); + return ENOENT; + } - memcpy (ret_threshold, t, sizeof (*ret_threshold)); - pthread_mutex_unlock (&threshold_lock); + memcpy(ret_threshold, t, sizeof(*ret_threshold)); + pthread_mutex_unlock(&threshold_lock); ret_threshold->next = NULL; - return (0); + return 0; } /* }}} int ut_search_threshold */ - -