libmultipath: do not stall on recv_packet()
authorHannes Reinecke <hare@suse.de>
Fri, 15 Nov 2013 10:29:36 +0000 (11:29 +0100)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Thu, 21 Nov 2013 08:33:14 +0000 (09:33 +0100)
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 <hare@suse.de>
libmultipath/uxsock.c

index ce89428..fcad56e 100644 (file)
@@ -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;