From: Florian Forster Date: Wed, 8 Feb 2012 15:38:01 +0000 (+0100) Subject: write_graphite plugin: Use swrite() instead of write(). X-Git-Tag: collectd-5.1.0~35^2~6 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=4c95b05e38f52460d7e89b98da5c2edddd37fc07;p=collectd.git write_graphite plugin: Use swrite() instead of write(). swrite() ensures that the entire buffer is written before the buffer is reset. Change-Id: I105d42d8ea5b71acd5a5e37b7cc4209045f28d47 --- 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); }