[CRIU] [PATCH 12/12] recv_fds: Switch to basic test over received fds

Cyrill Gorcunov gorcunov at openvz.org
Sun Mar 25 17:33:58 EDT 2012


As being reported by Pavel, using kcmp for received
fds test is an overkill. Simply add test over the number
of fds obtained.

Reported-by: Pavel Emelyanov <xemul at parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 include/util-net.h |    2 +-
 parasite-syscall.c |   13 ++-----------
 util-net.c         |    2 +-
 3 files changed, 4 insertions(+), 13 deletions(-)

diff --git a/include/util-net.h b/include/util-net.h
index 2289d0e..4dd08cf 100644
--- a/include/util-net.h
+++ b/include/util-net.h
@@ -41,7 +41,7 @@ static inline int recv_fd(int sock)
 	int fd, ret;
 
 	ret = recv_fds(sock, &fd, 1);
-	if (ret)
+	if (ret != 1)
 		return -1;
 
 	return fd;
diff --git a/parasite-syscall.c b/parasite-syscall.c
index 35562bb..fa30abd 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -610,7 +610,7 @@ int parasite_drain_fds_seized(struct parasite_ctl *ctl, int *fds, int *lfds, int
 	struct parasite_drain_fd args	= { };
 	parasite_status_t *st		= &args.status;
 	int ret = -1;
-	int sock, i;
+	int sock;
 
 	args.sun_len = gen_parasite_saddr(&args.saddr, (int)-2u);
 	args.nr_fds = nr_fds;
@@ -636,20 +636,11 @@ int parasite_drain_fds_seized(struct parasite_ctl *ctl, int *fds, int *lfds, int
 	}
 
 	ret = recv_fds(sock, lfds, nr_fds);
-	if (ret) {
+	if (ret != nr_fds) {
 		pr_err("Can't retrieve FDs from socket\n");
 		goto err;
 	}
 
-	/* Verify the descriptors do match */
-	for (i = 0; i < nr_fds; i++) {
-		pid_t me = getpid();
-		if (sys_kcmp(me, ctl->pid, KCMP_FILE, fds[i], lfds[i])) {
-			pr_err("File descriptors mismatch: (%d) %d (%d) %d\n",
-				me, ctl->pid, fds[i], lfds[i]);
-		}
-	}
-
 	ret = 0;
 err:
 	close(sock);
diff --git a/util-net.c b/util-net.c
index 1c1efae..110f60b 100644
--- a/util-net.c
+++ b/util-net.c
@@ -120,5 +120,5 @@ int recv_fds(int sock, int *fds, int nr_fds)
 		builtin_memcpy(&fds[i], fds_rx, sizeof(int) * min_fd);
 	}
 
-	return 0;
+	return min_fd;
 }
-- 
1.7.7.6



More information about the CRIU mailing list