X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fwrite_sensu.c;h=aae5d8bbfa73dc4929e2c51db1e5319d3807a7e4;hb=af512f0e603c15ced6b4f70db3dd0c2200b4a094;hp=2336541b63594f33d750ecd3203b8b0e6024f8d4;hpb=b333eb9557c96bdd2a336c33d623e428922a1046;p=collectd.git diff --git a/src/write_sensu.c b/src/write_sensu.c index 2336541b..aae5d8bb 100644 --- a/src/write_sensu.c +++ b/src/write_sensu.c @@ -24,6 +24,8 @@ * Fabrice A. Marie */ +#define _GNU_SOURCE + #include "collectd.h" #include "plugin.h" #include "common.h" @@ -37,53 +39,6 @@ #include #include -#ifndef HAVE_ASPRINTF -/* - * Uses asprintf() portable implementation from - * https://github.com/littlstar/asprintf.c/blob/master/ - * copyright (c) 2014 joseph werle under MIT license. - */ -#include -#include - -int vasprintf(char **str, const char *fmt, va_list args) { - int size = 0; - va_list tmpa; - // copy - va_copy(tmpa, args); - // apply variadic arguments to - // sprintf with format to get size - size = vsnprintf(NULL, size, fmt, tmpa); - // toss args - va_end(tmpa); - // return -1 to be compliant if - // size is less than 0 - if (size < 0) { return -1; } - // alloc with size plus 1 for `\0' - *str = (char *) malloc(size + 1); - // return -1 to be compliant - // if pointer is `NULL' - if (NULL == *str) { return -1; } - // format string with original - // variadic arguments and set new size - size = vsprintf(*str, fmt, args); - return size; -} - -int asprintf(char **str, const char *fmt, ...) { - int size = 0; - va_list args; - // init variadic argumens - va_start(args, fmt); - // format and get size - size = vasprintf(str, fmt, args); - // toss args - va_end(args); - return size; -} - -#endif - #define SENSU_HOST "localhost" #define SENSU_PORT "3030" @@ -258,7 +213,7 @@ static char *build_json_str_list(const char *tag, struct str_list const *list) / return ret_str; } /* }}} char *build_json_str_list*/ -int sensu_format_name2(char *ret, int ret_len, +static int sensu_format_name2(char *ret, int ret_len, const char *hostname, const char *plugin, const char *plugin_instance, const char *type, const char *type_instance, @@ -455,7 +410,7 @@ static char *sensu_value_to_json(struct sensu_host const *host, /* {{{ */ } // incorporate sensu tags from config if any - if (strlen(sensu_tags) != 0) { + if ((sensu_tags != NULL) && (strlen(sensu_tags) != 0)) { res = asprintf(&temp_str, "%s, %s", ret_str, sensu_tags); free(ret_str); if (res == -1) { @@ -550,7 +505,7 @@ static char *sensu_value_to_json(struct sensu_host const *host, /* {{{ */ * http://creativeandcritical.net/str-replace-c/ * copyright (c) Laird Shaw, under public domain. */ -char *replace_str(const char *str, const char *old, /* {{{ */ +static char *replace_str(const char *str, const char *old, /* {{{ */ const char *new) { char *ret, *r; @@ -752,7 +707,7 @@ static char *sensu_notification_to_json(struct sensu_host *host, /* {{{ */ } // incorporate sensu tags from config if any - if (strlen(sensu_tags) != 0) { + if ((sensu_tags != NULL) && (strlen(sensu_tags) != 0)) { res = asprintf(&temp_str, "%s, %s", ret_str, sensu_tags); free(ret_str); if (res == -1) {