[CRIU] [PATCH 3/3] protobuf: use generic show function for pstree

Kinsbursky Stanislav skinsbursky at openvz.org
Fri Jul 20 04:03:52 EDT 2012


From: Stanislav Kinsbursky <skinsbursky at openvz.org>

Now, there are two different functions: one for show and one for tasks
collect.

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
 cr-show.c |   53 ++++++++++++++++++-----------------------------------
 1 files changed, 18 insertions(+), 35 deletions(-)
-------------- next part --------------
diff --git a/cr-show.c b/cr-show.c
index a9f3417..654b21c 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -293,12 +293,10 @@ out:
 	pr_img_tail(CR_FD_CREDS);
 }
 
-static int show_collect_pstree(int fd_pstree, struct list_head *collect)
+static int collect_pstree(int fd_pstree, struct list_head *collect)
 {
 	PstreeEntry *e;
 
-	pr_img_head(CR_FD_PSTREE);
-
 	while (1) {
 		int ret;
 		struct pstree_item *item = NULL;
@@ -307,50 +305,33 @@ static int show_collect_pstree(int fd_pstree, struct list_head *collect)
 		ret = pb_read_eof(fd_pstree, &e, pstree_entry);
 		if (ret <= 0)
 			goto out;
-		pr_msg("pid: %8d ppid %8d pgid: %8d sid %8d  n_threads: %8d\n",
-		       (int)e->pid, (int)e->ppid, (int)e->pgid,
-		       (int)e->sid, (int)e->n_threads);
-
-		if (collect) {
-			item = xzalloc(sizeof(struct pstree_item));
-			if (!item)
-				return -1;
-
-			item->pid.virt = e->pid;
-			item->nr_threads = e->n_threads;
-			item->threads = xzalloc(sizeof(u32) * e->n_threads);
-			if (!item->threads) {
-				xfree(item);
-				return -1;
-			}
 
-			list_add_tail(&item->list, collect);
-		}
+		item = xzalloc(sizeof(struct pstree_item));
+		if (!item)
+			return -1;
 
-		if (e->n_threads) {
-			pr_msg("  \\\n");
-			pr_msg("   --- threads: ");
-			while (e->n_threads--) {
-				pr_msg(" %6d", (int)e->threads[e->n_threads]);
-				if (item)
-					item->threads[e->n_threads].virt = e->threads[e->n_threads];
-			}
-			pr_msg("\n");
+		item->pid.virt = e->pid;
+		item->nr_threads = e->n_threads;
+		item->threads = xzalloc(sizeof(u32) * e->n_threads);
+		if (!item->threads) {
+			xfree(item);
+			return -1;
 		}
 
+		list_add_tail(&item->list, collect);
+
 		pstree_entry__free_unpacked(e, NULL);
 	}
 
 out:
 	if (e)
 		pstree_entry__free_unpacked(e, NULL);
-	pr_img_tail(CR_FD_PSTREE);
 	return 0;
 }
 
 void show_pstree(int fd_pstree, struct cr_options *o)
 {
-	show_collect_pstree(fd_pstree, NULL);
+	pb_show_plain(fd_pstree, pstree_entry);
 }
 
 static void show_core_regs(int fd_core)
@@ -527,11 +508,13 @@ static int cr_show_all(struct cr_options *opts)
 	fd = open_image_ro(CR_FD_PSTREE);
 	if (fd < 0)
 		goto out;
+	ret = collect_pstree(fd, &pstree_list);
+	close(fd);
 
-	ret = show_collect_pstree(fd, &pstree_list);
-	if (ret)
+	fd = open_image_ro(CR_FD_PSTREE);
+	if (fd < 0)
 		goto out;
-
+	show_pstree(fd, NULL);
 	close(fd);
 
 	fd = open_image_ro(CR_FD_SK_QUEUES);


More information about the CRIU mailing list