[CRIU] [PATCH] restore: Factor out thread core opening

Pavel Emelyanov xemul at virtuozzo.com
Mon May 23 12:13:12 PDT 2016


Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/cr-restore.c | 46 ++++++++++++++++++++--------------------------
 1 file changed, 20 insertions(+), 26 deletions(-)

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index e05deb7..083e722 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -401,6 +401,23 @@ static int collect_zombie_pids()
 	return collect_child_pids(TASK_DEAD, &n_zombies);
 }
 
+static int open_core(int pid, CoreEntry **pcore)
+{
+	int ret;
+	struct cr_img *img;
+
+	img = open_image(CR_FD_CORE, O_RSTR, pid);
+	if (!img) {
+		pr_err("Can't open core data for %d", pid);
+		return -1;
+	}
+
+	ret = pb_read_one(img, pcore, PB_CORE);
+	close_image(img);
+
+	return ret <= 0 ? -1 : 0;
+}
+
 static int open_cores(int pid, CoreEntry *leader_core)
 {
 	int i, tpid;
@@ -415,22 +432,8 @@ static int open_cores(int pid, CoreEntry *leader_core)
 
 		if (tpid == pid)
 			cores[i] = leader_core;
-		else {
-			struct cr_img *img;
-
-			img = open_image(CR_FD_CORE, O_RSTR, tpid);
-			if (!img) {
-				pr_err("Can't open core data for thread %d\n", tpid);
-				goto err;
-			}
-
-			if (pb_read_one(img, &cores[i], PB_CORE) <= 0) {
-				close_image(img);
-				goto err;
-			}
-
-			close_image(img);
-		}
+		else if (open_core(tpid, &cores[i]))
+			goto err;
 	}
 
 	current->core = cores;
@@ -780,16 +783,7 @@ static inline int fork_with_pid(struct pstree_item *item)
 	pid_t pid = item->pid.virt;
 
 	if (item->pid.state != TASK_HELPER) {
-		struct cr_img *img;
-
-		img = open_image(CR_FD_CORE, O_RSTR, pid);
-		if (!img)
-			return -1;
-
-		ret = pb_read_one(img, &ca.core, PB_CORE);
-		close_image(img);
-
-		if (ret < 0)
+		if (open_core(pid, &ca.core))
 			return -1;
 
 		if (check_core(ca.core, item))
-- 
2.5.0


More information about the CRIU mailing list