From 4c95b05e38f52460d7e89b98da5c2edddd37fc07 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 8 Feb 2012 16:38:01 +0100 Subject: [PATCH] write_graphite plugin: Use swrite() instead of write(). swrite() ensures that the entire buffer is written before the buffer is reset. Change-Id: I105d42d8ea5b71acd5a5e37b7cc4209045f28d47 --- src/write_graphite.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/write_graphite.c b/src/write_graphite.c index 7a0bb12d..de2266e8 100644 --- a/src/write_graphite.c +++ b/src/write_graphite.c @@ -109,21 +109,22 @@ static void wg_reset_buffer (struct wg_callback *cb) static int wg_send_buffer (struct wg_callback *cb) { - int status = 0; + ssize_t status = 0; - status = write (cb->sock_fd, cb->send_buf, strlen (cb->send_buf)); + status = swrite (cb->sock_fd, cb->send_buf, strlen (cb->send_buf)); if (status < 0) { - ERROR ("write_graphite plugin: send failed with " - "status %i (%s)", - status, - strerror (errno)); + char errbuf[1024]; + ERROR ("write_graphite plugin: send failed with status %zi (%s)", + status, sstrerror (errno, errbuf, sizeof (errbuf))); + close (cb->sock_fd); cb->sock_fd = -1; return (-1); } + return (0); } -- 2.11.0