[CRIU] [PATCH v3 08/26] files: Receive real fd numbers using recv_fd_from_peer()

Kirill Tkhai ktkhai at virtuozzo.com
Mon Dec 5 06:08:37 PST 2016


Move reopen_fd_as() from receive_fd() to this function.
Note, that recv_fd_from_peer() has other callers, and
all of them are OK with receiving real fds (before,
they received arbitrary fds, and they OK with any fds).

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

diff --git a/criu/files.c b/criu/files.c
index 63190ec..64d4aa8 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -933,7 +933,10 @@ int recv_fd_from_peer(struct fdinfo_list_entry *fle)
 	}
 	fle->received = 1;
 
-	return fd;
+	if (reopen_fd_as(fle->fe->fd, fd) < 0)
+		return -1;
+
+	return fle->fe->fd;
 }
 
 int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle)
@@ -1046,7 +1049,7 @@ static int open_fd(int pid, struct fdinfo_list_entry *fle)
 
 static int receive_fd(int pid, struct fdinfo_list_entry *fle)
 {
-	int tmp;
+	int fd;
 	struct fdinfo_list_entry *flem;
 
 	flem = file_master(fle->desc);
@@ -1055,14 +1058,13 @@ static int receive_fd(int pid, struct fdinfo_list_entry *fle)
 
 	pr_info("\tReceive fd for %d\n", fle->fe->fd);
 
-	tmp = recv_fd_from_peer(fle);
-	if (tmp < 0) {
-		pr_err("Can't get fd %d\n", tmp);
+	fd = recv_fd_from_peer(fle);
+	if (fd < 0) {
+		pr_err("Can't get fd=%d, pid=%d\n", fle->fe->fd, fle->pid);
 		return -1;
 	}
 
-	if (reopen_fd_as(fle->fe->fd, tmp) < 0)
-		return -1;
+	BUG_ON(fd != fle->fe->fd);
 
 	if (fcntl(fle->fe->fd, F_SETFD, fle->fe->flags) == -1) {
 		pr_perror("Unable to set file descriptor flags");



More information about the CRIU mailing list