X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Fcommon.c;h=fba51ef8f73be8f8bbb174e55525e59e6e397eb0;hb=dc2eb041159b967838a2eb658cb256bc846c5264;hp=b2448086c53aadc0641b63bf7eef9b51e8c1decf;hpb=79593ed5e0a3def8e91be5b1de15a536af2d4a92;p=collectd.git diff --git a/src/daemon/common.c b/src/daemon/common.c index b2448086..fba51ef8 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -49,6 +49,8 @@ #include #include +#include + #if HAVE_NETINET_IN_H # include #endif @@ -270,9 +272,23 @@ ssize_t swrite (int fd, const void *buf, size_t count) const char *ptr; size_t nleft; ssize_t status; + struct pollfd pfd; ptr = (const char *) buf; nleft = count; + + /* checking for closed peer connection */ + pfd.fd = fd; + pfd.events = POLLIN | POLLHUP; + pfd.revents = 0; + 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; + } + } while (nleft > 0) { @@ -1154,6 +1170,9 @@ int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds) char *ptr; char *saveptr; + if ((buffer == NULL) || (vl == NULL) || (ds == NULL)) + return EINVAL; + i = -1; dummy = buffer; saveptr = NULL;