[CRIU] [PATCH 3/3] files: Use non-block __recv_fds() in recv_fd_from_peer()

Kirill Tkhai ktkhai at virtuozzo.com
Wed Jan 25 01:46:37 PST 2017


Save one syscall and analyze recvmsg() error code to check
that there is no data in the socket.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/files.c |   13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/criu/files.c b/criu/files.c
index c2246d576..ef38eb3f0 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -888,22 +888,17 @@ static int plant_fd(struct fdinfo_list_entry *fle, int fd)
 int recv_fd_from_peer(struct fdinfo_list_entry *fle)
 {
 	struct fdinfo_list_entry *tmp;
-	int fd, ret, tsock, count;
+	int fd, ret, tsock;
 
 	if (fle->received)
 		return 0;
 
 	tsock = get_service_fd(TRANSPORT_FD_OFF);
-
 	do {
-		if (ioctl(tsock, FIONREAD, &count) < 0) {
-			pr_perror("Can't do ioctl on transport sock: pid=%d\n", fle->pid);
-			return -1;
-		} else if (count == 0)
+		ret = __recv_fds(tsock, &fd, 1, (void *)&tmp, sizeof(struct fdinfo_list_entry *), MSG_DONTWAIT);
+		if (ret == -EAGAIN || ret == -EWOULDBLOCK)
 			return 1;
-
-		ret = recv_fds(tsock, &fd, 1, (void *)&tmp, sizeof(struct fdinfo_list_entry *));
-		if (ret)
+		else if (ret)
 			return -1;
 
 		pr_info("Further fle=%p, pid=%d\n", tmp, fle->pid);



More information about the CRIU mailing list