diff --git a/src/utils_cmd_flush.c b/src/utils_cmd_flush.c
index b1973be55bcdcaa5ab863f9de6b6f6092d9e3434..6fa8b7bf00b5d0b68979b4e828e1f7093e32f5dc 100644 (file)
--- a/src/utils_cmd_flush.c
+++ b/src/utils_cmd_flush.c
#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;
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 */