From: Hannes Reinecke Date: Fri, 15 Nov 2013 10:29:36 +0000 (+0100) Subject: libmultipath: do not stall on recv_packet() X-Git-Tag: 0.5.0~45 X-Git-Url: https://git.opensvc.com/gitweb.cgi?p=multipath-tools%2F.git;a=commitdiff_plain;h=66f6b702a4a194e317bfaa8c4aa5aaf8f4b588e5 libmultipath: do not stall on recv_packet() The CLI socket might have been closed or the daemon might have been terminated by systemd without closing the CLI socket. Hence we need to poll the socket if further data is avalailable, otherwise the read() call will hang. Signed-off-by: Hannes Reinecke --- diff --git a/libmultipath/uxsock.c b/libmultipath/uxsock.c index ce89428b..fcad56e5 100644 --- a/libmultipath/uxsock.c +++ b/libmultipath/uxsock.c @@ -107,9 +107,24 @@ size_t write_all(int fd, const void *buf, size_t len) size_t read_all(int fd, void *buf, size_t len) { size_t total = 0; + ssize_t n; + int ret; + struct pollfd pfd; while (len) { - ssize_t n = read(fd, buf, len); + pfd.fd = fd; + pfd.events = POLLIN; + ret = poll(&pfd, 1, 1000); + if (!ret) { + errno = ETIMEDOUT; + return total; + } else if (ret < 0) { + if (errno == EINTR) + continue; + return total; + } else if (!pfd.revents & POLLIN) + continue; + n = read(fd, buf, len); if (n < 0) { if ((errno == EINTR) || (errno == EAGAIN)) continue;