[CRIU] [PATCH 2/4] show: add helper for reading and printing of images binary data

Kinsbursky Stanislav skinsbursky at openvz.org
Wed Jul 25 08:40:34 EDT 2012


Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>

---
 cr-show.c         |   17 +++++++++++++++++
 include/crtools.h |    1 +
 sk-queue.c        |   14 +-------------
 3 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/cr-show.c b/cr-show.c
index f54c0d5..3053dcd 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -165,6 +165,23 @@ void print_data(unsigned long addr, unsigned char *data, size_t size)
 	}
 }
 
+void print_image_data(int fd, unsigned int length)
+{
+	void *data;
+	int ret;
+
+	data = xmalloc(length);
+	if (!data)
+		return;
+	ret = read_img_buf(fd, (unsigned char *)data, length);
+	if (ret < 0) {
+		xfree(data);
+		return;
+	}
+	print_data(0, (unsigned char *)data, length);
+	xfree(data);
+}
+
 void show_pages(int fd_pages, struct cr_options *o)
 {
 	pr_img_head(CR_FD_PAGES);
diff --git a/include/crtools.h b/include/crtools.h
index ded767d..d2a1dce 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -127,6 +127,7 @@ int check_img_inventory(void);
 int write_img_inventory(void);
 
 extern void print_data(unsigned long addr, unsigned char *data, size_t size);
+extern void print_image_data(int fd, unsigned int length);
 extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX];
 
 extern int open_image_dir(void);
diff --git a/sk-queue.c b/sk-queue.c
index f009017..a40be05 100644
--- a/sk-queue.c
+++ b/sk-queue.c
@@ -175,25 +175,13 @@ void show_sk_queues(int fd, struct cr_options *o)
 
 	pr_img_head(CR_FD_SK_QUEUES);
 	while (1) {
-		void *data;
-
 		ret = pb_read_eof(fd, &pe, sk_packet_entry);
 		if (ret <= 0)
 			break;
 		pr_msg("pkt for %u length %u bytes\n",
 			pe->id_for, (unsigned int)pe->length);
-
-		data = xmalloc(pe->length);
-		if (!data)
-			break;
-		ret = read_img_buf(fd, (unsigned char *)data, pe->length);
-		if (ret < 0) {
-			xfree(data);
-			break;
-		}
-		print_data(0, (unsigned char *)data, pe->length);
+		print_image_data(fd, pe->length);
 		sk_packet_entry__free_unpacked(pe, NULL);
-		xfree(data);
 	}
 	pr_img_tail(CR_FD_SK_QUEUES);
 }



More information about the CRIU mailing list