X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_cmd_putnotif.c;h=ec91419d8ad523fe3ff37979934663d285e4959c;hb=99eb08be924850cf76e3dece205d5cbf9c7d74c7;hp=5a9faff2321e315188e370c7b5508fb17a108576;hpb=fd9c88963b04c9e9050a952ba0f018493e8b7638;p=collectd.git diff --git a/src/utils_cmd_putnotif.c b/src/utils_cmd_putnotif.c index 5a9faff2..ec91419d 100644 --- a/src/utils_cmd_putnotif.c +++ b/src/utils_cmd_putnotif.c @@ -24,14 +24,18 @@ #include "plugin.h" #include "utils_parse_option.h" +#include "utils_cmd_putnotif.h" #define print_to_socket(fh, ...) \ - if (fprintf (fh, __VA_ARGS__) < 0) { \ - char errbuf[1024]; \ - WARNING ("handle_putnotif: failed to write to socket #%i: %s", \ - fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \ - return -1; \ - } + do { \ + if (fprintf (fh, __VA_ARGS__) < 0) { \ + char errbuf[1024]; \ + WARNING ("handle_putnotif: failed to write to socket #%i: %s", \ + fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \ + return -1; \ + } \ + fflush(fh); \ + } while (0) static int set_option_severity (notification_t *n, const char *value) { @@ -49,13 +53,18 @@ static int set_option_severity (notification_t *n, const char *value) static int set_option_time (notification_t *n, const char *value) { - time_t tmp; - - tmp = (time_t) atoi (value); - if (tmp <= 0) + char *endptr = NULL; + double tmp; + + errno = 0; + tmp = strtod (value, &endptr); + if ((errno != 0) /* Overflow */ + || (endptr == value) /* Invalid string */ + || (endptr == NULL) /* This should not happen */ + || (*endptr != 0)) /* Trailing chars */ return (-1); - n->time = tmp; + n->time = DOUBLE_TO_CDTIME_T (tmp); return (0); } /* int set_option_time */