Blob Blame History Raw
From 2c909b78d8226d4d76f53df1091af40ec5fc54a1 Mon Sep 17 00:00:00 2001
From: Ryan McCabe <rmccabe@redhat.com>
Date: Thu, 25 May 2017 13:34:05 -0400
Subject: [PATCH] fence_virtd: Fix select logic in listener plugins

Don't fail causing the daemon to exit when select() fails with errors
that indicate we should retry.

Signed-off-by: Ryan McCabe <rmccabe@redhat.com>
---
 common/fdops.c  |  8 +++++---
 server/mcast.c  | 10 ++--------
 server/serial.c |  4 +---
 server/tcp.c    |  2 +-
 4 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/common/fdops.c b/common/fdops.c
index bff8bec..3d89ba1 100644
--- a/common/fdops.c
+++ b/common/fdops.c
@@ -41,9 +41,11 @@ _select_retry(int fdmax, fd_set * rfds, fd_set * wfds, fd_set * xfds,
 
 	while (1) {
 		rv = select(fdmax, rfds, wfds, xfds, timeout);
-		if ((rv == -1) && (errno == EINTR))
-			/* return on EBADF/EINVAL/ENOMEM; continue on EINTR */
-			continue;
+		if (rv == -1) {
+			/* return on EBADF/EINVAL/ENOMEM; continue on EINTR/EAGAIN/ENOMEM */
+			if (errno == EINTR || errno == EAGAIN || errno == ENOMEM)
+				continue;
+		}
 		return rv;
 	}
 }
diff --git a/server/mcast.c b/server/mcast.c
index f6181aa..8f58fa6 100644
--- a/server/mcast.c
+++ b/server/mcast.c
@@ -350,16 +350,10 @@ mcast_dispatch(listener_context_t c, struct timeval *timeout)
 	FD_ZERO(&rfds);
 	FD_SET(info->mc_sock, &rfds);
 
-	n = select((info->mc_sock)+1, &rfds, NULL, NULL, timeout);
-	if (n < 0)
+	n = _select_retry((info->mc_sock)+1, &rfds, NULL, NULL, timeout);
+	if (n <= 0)
 		return n;
 	
-	/* 
-	 * If no requests, we're done 
-	 */
-	if (n == 0)
-		return 0;
-
 	slen = sizeof(sin);
 	len = recvfrom(info->mc_sock, &data, sizeof(data), 0,
 		       (struct sockaddr *)&sin, &slen);
diff --git a/server/serial.c b/server/serial.c
index 558292a..70eb22b 100644
--- a/server/serial.c
+++ b/server/serial.c
@@ -272,10 +272,8 @@ serial_dispatch(listener_context_t c, struct timeval *timeout)
 	if (info->wake_fd > max)
 		max = info->wake_fd;
 
-	n = select(max+1, &rfds, NULL, NULL, timeout);
+	n = _select_retry(max+1, &rfds, NULL, NULL, timeout);
 	if (n < 0) {
-		if (errno == ETIMEDOUT || errno == EINTR || errno == EAGAIN)
-			return 0;
 		dbg_printf(2, "select: %s\n", strerror(errno));
 		return n;
 	}
diff --git a/server/tcp.c b/server/tcp.c
index fc9caca..0002e8f 100644
--- a/server/tcp.c
+++ b/server/tcp.c
@@ -276,7 +276,7 @@ tcp_dispatch(listener_context_t c, struct timeval *timeout)
 	FD_ZERO(&rfds);
 	FD_SET(info->listen_sock, &rfds);
 
-	n = select(info->listen_sock + 1, &rfds, NULL, NULL, timeout);
+	n = _select_retry(info->listen_sock + 1, &rfds, NULL, NULL, timeout);
 	if (n <= 0)
 		return n;