X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fdaemon%2Fcommon.c;h=64dbee6f604df866de5b1fbeb316624876833512;hp=40822d0c8f4576594bb3a29c9a3cfde772443822;hb=786a6be461cf58ef2b8c57974cad2a79ba2ee82c;hpb=7269bf71e30f0a70a9eb954f6b0a6fe1b10eb6e5 diff --git a/src/daemon/common.c b/src/daemon/common.c index 40822d0c..64dbee6f 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -267,8 +267,10 @@ ssize_t swrite(int fd, const void *buf, size_t count) { ptr = (const char *)buf; nleft = count; - if (fd < 0) - return (-1); + if (fd < 0) { + errno = EINVAL; + return errno; + } /* checking for closed peer connection */ pfd.fd = fd; @@ -277,10 +279,9 @@ ssize_t swrite(int fd, const void *buf, size_t count) { if (poll(&pfd, 1, 0) > 0) { char buffer[32]; 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 -1; + /* 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; } } @@ -291,7 +292,7 @@ ssize_t swrite(int fd, const void *buf, size_t count) { continue; if (status < 0) - return (status); + return errno ? errno : status; nleft = nleft - ((size_t)status); ptr = ptr + ((size_t)status);