X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Futils_cmd_flush.c;h=6fa8b7bf00b5d0b68979b4e828e1f7093e32f5dc;hb=a019b6c8144745db63c599680bd693ac02f11666;hp=b1973be55bcdcaa5ab863f9de6b6f6092d9e3434;hpb=917343b099777d5aae031c5062b01e4d3a694b5a;p=collectd.git diff --git a/src/utils_cmd_flush.c b/src/utils_cmd_flush.c index b1973be5..6fa8b7bf 100644 --- a/src/utils_cmd_flush.c +++ b/src/utils_cmd_flush.c @@ -25,6 +25,14 @@ #include "common.h" #include "plugin.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; \ + } + int handle_flush (FILE *fh, char **fields, int fields_num) { int success = 0; @@ -66,22 +74,21 @@ int handle_flush (FILE *fh, char **fields, int fields_num) if (status != 0) { - fprintf (fh, "-1 Cannot parse option %s\n", option); - fflush (fh); + print_to_socket (fh, "-1 Cannot parse option %s\n", option); return (-1); } } if ((success + error) > 0) { - fprintf (fh, "0 Done: %i successful, %i errors\n", success, error); + print_to_socket (fh, "0 Done: %i successful, %i errors\n", + success, error); } else { plugin_flush_all (timeout); - fprintf (fh, "0 Done\n"); + print_to_socket (fh, "0 Done\n"); } - fflush (fh); return (0); } /* int handle_flush */