From 4121560bad9c9de25b70095661ad633c573c6099 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 4 Jun 2014 21:14:20 +1000 Subject: [PATCH] Use MSG_WAITALL on reads to more reliably detect closed unix sockets --- src/libckpool.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libckpool.c b/src/libckpool.c index 28fe3c8d..934f4be5 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -637,8 +637,8 @@ int read_length(int sockd, void *buf, int len) return -1; } while (len) { - ret = read(sockd, buf + ofs, len); - if (unlikely(ret < 0)) + ret = recv(sockd, buf + ofs, len, MSG_WAITALL); + if (unlikely(ret < 1)) return -1; ofs += ret; len -= ret; @@ -655,7 +655,7 @@ char *_recv_unix_msg(int sockd, const char *file, const char *func, const int li uint32_t msglen; int ret; - ret = wait_read_select(sockd, 60); + ret = wait_read_select(sockd, 5); if (unlikely(ret < 1)) { LOGERR("Select1 failed in recv_unix_msg"); goto out; @@ -673,13 +673,13 @@ char *_recv_unix_msg(int sockd, const char *file, const char *func, const int li } buf = ckalloc(msglen + 1); buf[msglen] = 0; - ret = wait_read_select(sockd, 60); + ret = wait_read_select(sockd, 5); if (unlikely(ret < 1)) { LOGERR("Select2 failed in recv_unix_msg"); goto out; } ret = read_length(sockd, buf, msglen); - if (unlikely(ret < 0)) { + if (unlikely(ret < (int)msglen)) { LOGERR("Failed to read %d bytes in recv_unix_msg", msglen); dealloc(buf); }