X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcollectdctl.c;h=1ced5838bcfb9d03c996392132ed1183f638a15c;hb=93c4facaf7b6e35e032c3d46631097e34891d588;hp=4b0db2a7e883c721f0ad49eb14dceddedb84e7c6;hpb=662c44a84ae3daecd4ffdea940fffce35a41b52a;p=collectd.git diff --git a/src/collectdctl.c b/src/collectdctl.c index 4b0db2a7..1ced5838 100644 --- a/src/collectdctl.c +++ b/src/collectdctl.c @@ -25,6 +25,7 @@ #include "config.h" #endif +#include #include #include #include @@ -65,7 +66,7 @@ #endif #endif /* NAN_ZERO_ZERO */ -#include "libcollectdclient/collectd/client.h" +#include "collectd/client.h" #ifndef PREFIX #define PREFIX "/opt/" PACKAGE_NAME @@ -80,6 +81,22 @@ extern char *optarg; extern int optind; +/* ssnprintf returns zero on success, one if truncation occurred + and a negative integer onerror. */ +static int _ssnprintf(char *str, size_t sz, const char *format, ...) { + va_list ap; + va_start(ap, format); + + int ret = vsnprintf(str, sz, format, ap); + + va_end(ap); + + if (ret < 0) { + return ret; + } + return (size_t)ret >= sz; +} /* int _ssnprintf */ + __attribute__((noreturn)) static void exit_usage(const char *name, int status) { fprintf( (status == 0) ? stdout : stderr, @@ -166,7 +183,7 @@ static int parse_identifier(lcc_connection_t *c, const char *value, } hostname[sizeof(hostname) - 1] = '\0'; - snprintf(ident_str, sizeof(ident_str), "%s/%s", hostname, value); + _ssnprintf(ident_str, sizeof(ident_str), "%s/%s", hostname, value); ident_str[sizeof(ident_str) - 1] = '\0'; } else { strncpy(ident_str, value, sizeof(ident_str)); @@ -543,7 +560,7 @@ int main(int argc, char **argv) { switch (opt) { case 's': - snprintf(address, sizeof(address), "unix:%s", optarg); + _ssnprintf(address, sizeof(address), "unix:%s", optarg); address[sizeof(address) - 1] = '\0'; break; case 'h':