From fadd45ecb0eabd5629c3ef5f93d05a1dac25ce73 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 22 Dec 2016 10:52:44 +0100 Subject: [PATCH] src/daemon/common.c: Change swrite() to return errno if possible. --- src/daemon/common.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/daemon/common.c b/src/daemon/common.c index 0aa5345b..1fa99eb2 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -271,8 +271,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; @@ -281,10 +283,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; } } @@ -295,7 +296,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); -- 2.30.2