From: Florian Forster Date: Wed, 29 Sep 2010 15:59:48 +0000 (+0200) Subject: src/utils_cache.c: Minor cleanups. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=13e1d170b1ce9d8289fb041a5c6382985a0e772c;p=collectd.git src/utils_cache.c: Minor cleanups. --- diff --git a/src/utils_cache.c b/src/utils_cache.c index b7eacf3d..0e9bdbef 100644 --- a/src/utils_cache.c +++ b/src/utils_cache.c @@ -206,37 +206,40 @@ static int uc_send_notification (const char *name) /* if the associated threshold has a missing message, then use custom * message. FIXME: we do a threshold_search here and in uc_check_timeout * (calling ut_check_interesting, but we really need to do this once */ - if ( !ut_search_threshold(&vl, &th) && - (th.missing_message != NULL) ) + status = ut_search_threshold (&vl, &th); + while ((status == 0) && (th.missing_message != NULL)) { char msg[NOTIF_MAX_MSG_LEN]; char temp[NOTIF_MAX_MSG_LEN]; + char missing_str[32] = ""; sstrncpy (msg, th.missing_message, sizeof (msg)); - (void) ut_build_message (msg, NOTIF_MAX_MSG_LEN, th.missing_message, - &ds, 0, &vl, ce->values_gauge, + status = ut_build_message (msg, sizeof (msg), + /* format = */ th.missing_message, + &ds, /* ds index = */ 0, + &vl, ce->values_gauge, &n, &th); + if (status != 0) + break; -#define REPLACE_FIELD(t,v) \ - if (subst_string (temp, sizeof (temp), msg, t, v) != NULL) \ - sstrncpy (msg, temp, sizeof (msg)); - - char itoa_temp[NOTIF_MAX_MSG_LEN]; -#define ITOA(string,i) \ - memset(string,0x00,sizeof(string)); \ - snprintf(string, sizeof(string), "%i", i); + (void) ssnprintf (missing_str, sizeof (missing_str), "%li", + (long) (n.time - ce->last_update)); - ITOA(itoa_temp, (int)(n.time - ce->last_update)) - REPLACE_FIELD("%{missing}", itoa_temp) + if (subst_string (temp, sizeof (temp), msg, + "%{missing}", missing_str) != NULL) + sstrncpy (msg, temp, sizeof (msg)); - (void) ssnprintf (n.message, sizeof (n.message), - "%s", msg); + sstrncpy (n.message, msg, sizeof (n.message)); + break; } - else + + /* "ut_search_threshold" returned an error, there is no "missing_message" or + * "ut_build_message" failed. Use the generic default. */ + if ((status != 0) || (th.missing_message == NULL)) { ssnprintf (n.message, sizeof (n.message), - "%s has not been updated for %i seconds.", name, - (int) (n.time - ce->last_update)); + "\"%s\" has not been updated for %li seconds.", name, + (long) (n.time - ce->last_update)); } pthread_mutex_unlock (&cache_lock);