X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_cmd_flush.c;h=4e7526be5a014df57b87a71d1aa136da07ab75c3;hb=b8a525a80874e431e1a076e1b45ab3d221a8a702;hp=0e7b350f581f02f07ccaf234c1ec0c225011b33d;hpb=e628f39838a67b40d52dfb8425b4d8474fbd0550;p=collectd.git diff --git a/src/utils_cmd_flush.c b/src/utils_cmd_flush.c index 0e7b350f..4e7526be 100644 --- a/src/utils_cmd_flush.c +++ b/src/utils_cmd_flush.c @@ -27,12 +27,15 @@ #include "utils_parse_option.h" #define print_to_socket(fh, ...) \ - if (fprintf (fh, __VA_ARGS__) < 0) { \ - char errbuf[1024]; \ - WARNING ("handle_flush: 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_flush: failed to write to socket #%i: %s", \ + fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \ + return -1; \ + } \ + fflush(fh); \ + } while (0) static int add_to_array (char ***array, int *array_num, char *value) { @@ -54,7 +57,7 @@ int handle_flush (FILE *fh, char *buffer) int success = 0; int error = 0; - int timeout = -1; + double timeout = 0.0; char **plugins = NULL; int plugins_num = 0; char **identifiers = NULL; @@ -106,9 +109,9 @@ int handle_flush (FILE *fh, char *buffer) errno = 0; endptr = NULL; - timeout = strtol (opt_value, &endptr, 0); + timeout = strtod (opt_value, &endptr); - if ((endptr == opt_value) || (errno != 0)) + if ((endptr == opt_value) || (errno != 0) || (!isfinite (timeout))) { print_to_socket (fh, "-1 Invalid value for option `timeout': " "%s\n", opt_value); @@ -116,8 +119,10 @@ int handle_flush (FILE *fh, char *buffer) sfree (identifiers); return (-1); } - else if (timeout <= 0) - timeout = -1; + else if (timeout < 0.0) + { + timeout = 0.0; + } } else { @@ -149,7 +154,9 @@ int handle_flush (FILE *fh, char *buffer) int status; identifier = identifiers[j]; - status = plugin_flush (plugin, timeout, identifier); + status = plugin_flush (plugin, + DOUBLE_TO_CDTIME_T (timeout), + identifier); if (status == 0) success++; else