[CRIU] [PATCH 1/12] files.c: Use RW API

Pavel Emelyanov xemul at parallels.com
Tue Feb 7 06:49:04 EST 2012


Signed-off-by: Pavel Emelyanov <xemul at parallels.com>

---
-------------- next part --------------
From 64fac336355500f6ba8b5a7599ced0947f61a04a Mon Sep 17 00:00:00 2001
From: Pavel Emelyanov <pavel at xemulnb.(none)>
Date: Mon, 6 Feb 2012 13:25:06 +0400
Subject: [PATCH 01/12] files.c -> new rw api

---
 files.c |   20 ++++++++------------
 1 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/files.c b/files.c
index 2350049..1b700e4 100644
--- a/files.c
+++ b/files.c
@@ -156,7 +156,7 @@ static int collect_fd(int pid, struct fdinfo_entry *e)
 
 int prepare_fd_pid(int pid)
 {
-	int fdinfo_fd;
+	int fdinfo_fd, ret = 0;
 	u32 type = 0;
 
 	fdinfo_fd = open_image_ro(CR_FD_FDINFO, pid);
@@ -168,29 +168,25 @@ int prepare_fd_pid(int pid)
 	}
 
 	while (1) {
-		int ret;
 		struct fdinfo_entry e;
 
-		ret = read(fdinfo_fd, &e, sizeof(e));
-		if (ret == 0)
+		ret = read_img_eof(fdinfo_fd, &e);
+		if (ret <= 0)
 			break;
-		if (ret != sizeof(e)) {
-			pr_perror("%d: Read fdinfo failed %d (expected %li)",
-				  pid, ret, sizeof(e));
-			return -1;
-		}
+
 		if (e.len)
 			lseek(fdinfo_fd, e.len, SEEK_CUR);
 
 		if (fd_is_special(&e))
 			continue;
 
-		if (collect_fd(pid, &e))
-			return -1;
+		ret = collect_fd(pid, &e);
+		if (ret < 0)
+			break;
 	}
 
 	close(fdinfo_fd);
-	return 0;
+	return ret;
 }
 
 static int open_fe_fd(struct fdinfo_entry *fe, int fd)
-- 
1.6.5.2


More information about the CRIU mailing list