X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Futils_cmd_listval.c;h=afbd01d0ceed106dd2b4852d06ca5b7a76e3dcea;hb=4d370741101aeb037ae52f3529a4a0869e0dc08a;hp=d9dc5c1f7452506d8e426786911f19a5d4711244;hpb=6e430c3eea4a35438b634ae00fc32052b30ec9ae;p=collectd.git diff --git a/src/utils_cmd_listval.c b/src/utils_cmd_listval.c index d9dc5c1f..afbd01d0 100644 --- a/src/utils_cmd_listval.c +++ b/src/utils_cmd_listval.c @@ -25,6 +25,7 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" @@ -33,8 +34,7 @@ #include "utils_parse_option.h" #define free_everything_and_return(status) do { \ - size_t j; \ - for (j = 0; j < number; j++) { \ + for (size_t j = 0; j < number; j++) { \ sfree(names[j]); \ names[j] = NULL; \ } \ @@ -44,12 +44,15 @@ } while (0) #define print_to_socket(fh, ...) \ - if (fprintf (fh, __VA_ARGS__) < 0) { \ - char errbuf[1024]; \ - WARNING ("handle_listval: failed to write to socket #%i: %s", \ - fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \ - free_everything_and_return (-1); \ - } + do { \ + if (fprintf (fh, __VA_ARGS__) < 0) { \ + char errbuf[1024]; \ + WARNING ("handle_listval: failed to write to socket #%i: %s", \ + fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \ + free_everything_and_return (-1); \ + } \ + fflush(fh); \ + } while (0) int handle_listval (FILE *fh, char *buffer) { @@ -57,7 +60,6 @@ int handle_listval (FILE *fh, char *buffer) char **names = NULL; cdtime_t *times = NULL; size_t number = 0; - size_t i; int status; DEBUG ("utils_cmd_listval: handle_listval (fh = %p, buffer = %s);", @@ -94,7 +96,7 @@ int handle_listval (FILE *fh, char *buffer) print_to_socket (fh, "%i Value%s found\n", (int) number, (number == 1) ? "" : "s"); - for (i = 0; i < number; i++) + for (size_t i = 0; i < number; i++) print_to_socket (fh, "%.3f %s\n", CDTIME_T_TO_DOUBLE (times[i]), names[i]);