From bbe5133c16fb12c033cc4375db4c4f9f1f1506e9 Mon Sep 17 00:00:00 2001 From: Pavel Rochnyack Date: Tue, 4 Jul 2017 16:14:05 +0700 Subject: [PATCH] Proper check for `swrite()` return value The `swrite()` can return positive value from `errno` in case of error. --- src/mcelog.c | 2 +- src/multimeter.c | 2 +- src/ntpd.c | 2 +- src/ted.c | 2 +- src/write_tsdb.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mcelog.c b/src/mcelog.c index 6b10b04c..ae5a7f54 100644 --- a/src/mcelog.c +++ b/src/mcelog.c @@ -257,7 +257,7 @@ static int socket_write(socket_adapter_t *self, const char *msg, const size_t len) { int ret = 0; pthread_rwlock_rdlock(&self->lock); - if (swrite(self->sock_fd, msg, len) < 0) + if (swrite(self->sock_fd, msg, len) != 0) ret = -1; pthread_rwlock_unlock(&self->lock); return ret; diff --git a/src/multimeter.c b/src/multimeter.c index 72b0fed9..fc69e02d 100644 --- a/src/multimeter.c +++ b/src/multimeter.c @@ -62,7 +62,7 @@ static int multimeter_read_value(double *value) { struct timeval time_now; status = swrite(fd, "D", 1); - if (status < 0) { + if (status != 0) { ERROR("multimeter plugin: swrite failed."); return -1; } diff --git a/src/ntpd.c b/src/ntpd.c index 48d7aa72..0faf2a2a 100644 --- a/src/ntpd.c +++ b/src/ntpd.c @@ -669,7 +669,7 @@ static int ntpd_send_request(int req_code, int req_items, int req_size, (void *)req_data); status = swrite(sd, (const char *)&req, REQ_LEN_NOMAC); - if (status < 0) { + if (status != 0) { DEBUG("`swrite' failed. Closing socket #%i", sd); close(sd); sock_descr = sd = -1; diff --git a/src/ted.c b/src/ted.c index 94b4e3ab..3b64b75f 100644 --- a/src/ted.c +++ b/src/ted.c @@ -88,7 +88,7 @@ static int ted_read_value(double *ret_power, double *ret_voltage) { status = write(fd, pkt_request, sizeof(pkt_request)); if (status <= 0) { - ERROR("ted plugin: swrite failed."); + ERROR("ted plugin: write failed."); return -1; } diff --git a/src/write_tsdb.c b/src/write_tsdb.c index 10f636c5..eb6ceb3f 100644 --- a/src/write_tsdb.c +++ b/src/write_tsdb.c @@ -111,7 +111,7 @@ static int wt_send_buffer(struct wt_callback *cb) { ssize_t status = 0; status = swrite(cb->sock_fd, cb->send_buf, strlen(cb->send_buf)); - if (status < 0) { + if (status != 0) { char errbuf[1024]; ERROR("write_tsdb plugin: send failed with status %zi (%s)", status, sstrerror(errno, errbuf, sizeof(errbuf))); -- 2.30.2