[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[dm-devel] [PATCH 05/13] 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 <hare suse de>
---
 libmultipath/uxsock.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/libmultipath/uxsock.c b/libmultipath/uxsock.c
index ce89428..fcad56e 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;
-- 
1.8.1.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]