From: Pavel Rochnyack Date: Mon, 31 Jul 2017 05:21:24 +0000 (+0700) Subject: Proper return value from 'swrite()' when connection has been closed X-Git-Tag: collectd-5.8.0~76^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=243163d9a20ed9961f6c2eefe59b411b5c39d707;p=collectd.git Proper return value from 'swrite()' when connection has been closed According to POSIX, errno is set only if 'recv()' returns -1. When connection has been closed, 'recv()' returns 0 and errno left untouched. For functions which check errno value after 'swrite()', errno now is set to ECONNRESET, so they produce correct message 'Connection reset by peer'. --- diff --git a/src/daemon/common.c b/src/daemon/common.c index 3ae61d85..6c856a6b 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -269,7 +269,8 @@ ssize_t swrite(int fd, const void *buf, size_t count) { if (recv(fd, buffer, sizeof(buffer), MSG_PEEK | MSG_DONTWAIT) == 0) { /* if recv returns zero (even though poll() said there is data to be * read), that means the connection has been closed */ - return errno ? errno : -1; + errno = ECONNRESET; + return -1; } }