[CRIU] [PATCH] show: Remove deprecated code

Pavel Emelyanov xemul at virtuozzo.com
Mon Feb 8 02:29:32 PST 2016


The 'show' action has been deprecated since 1.6, let's finally drop it.

The print_data() routine is kept for yet another (to be deprecated too)
feature called 'criu exec'.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 Makefile.crtools     |   1 -
 cr-exec.c            |   1 +
 cr-show.c            | 574 ---------------------------------------------------
 crtools.c            |   7 +-
 image-desc.c         |   1 -
 include/cr-show.h    |  25 ---
 include/crtools.h    |   1 -
 include/namespaces.h |   1 -
 include/protobuf.h   |  14 --
 include/util.h       |   2 +
 ipc_ns.c             |  43 ----
 namespaces.c         |  62 ------
 protobuf.c           | 465 -----------------------------------------
 sk-queue.c           |   6 -
 sk-tcp.c             |  12 --
 tun.c                |   1 -
 util.c               |  74 +++++++
 17 files changed, 82 insertions(+), 1208 deletions(-)
 delete mode 100644 cr-show.c
 delete mode 100644 include/cr-show.h

diff --git a/Makefile.crtools b/Makefile.crtools
index 5788ef0..b073c42 100644
--- a/Makefile.crtools
+++ b/Makefile.crtools
@@ -10,7 +10,6 @@ obj-y	+= tun.o
 obj-y	+= proc_parse.o
 obj-y	+= sysfs_parse.o
 obj-y	+= cr-dump.o
-obj-y	+= cr-show.o
 obj-y	+= cr-check.o
 obj-y	+= cr-dedup.o
 obj-y	+= util.o
diff --git a/cr-exec.c b/cr-exec.c
index 8beb80f..83ff192 100644
--- a/cr-exec.c
+++ b/cr-exec.c
@@ -6,6 +6,7 @@
 #include "parasite-syscall.h"
 #include "vma.h"
 #include "log.h"
+#include "util.h"
 
 struct syscall_exec_desc {
 	char *name;
diff --git a/cr-show.c b/cr-show.c
deleted file mode 100644
index 91d4d09..0000000
diff --git a/crtools.c b/crtools.c
index 4406029..9cf7475 100644
--- a/crtools.c
+++ b/crtools.c
@@ -661,8 +661,11 @@ int main(int argc, char *argv[], char *envp[])
 		return ret != 0;
 	}
 
-	if (!strcmp(argv[optind], "show"))
-		return cr_show(pid) != 0;
+	if (!strcmp(argv[optind], "show")) {
+		pr_msg("The \"show\" action is deprecated by the CRIT utility.\n");
+		pr_msg("To view an image use the \"crit decode -i $name --pretty\" command.\n");
+		return -1;
+	}
 
 	if (!strcmp(argv[optind], "check"))
 		return cr_check() != 0;
diff --git a/image-desc.c b/image-desc.c
index 6770675..de0fe93 100644
--- a/image-desc.c
+++ b/image-desc.c
@@ -1,7 +1,6 @@
 #include <stdlib.h>
 
 #include "image-desc.h"
-#include "cr-show.h"
 #include "magic.h"
 #include "image.h"
 
diff --git a/include/cr-show.h b/include/cr-show.h
deleted file mode 100644
index 6ebdb4c..0000000
diff --git a/include/crtools.h b/include/crtools.h
index eaa70dc..62f550cf 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -21,7 +21,6 @@ extern int prepare_inventory(InventoryEntry *he);
 extern int cr_dump_tasks(pid_t pid);
 extern int cr_pre_dump_tasks(pid_t pid);
 extern int cr_restore_tasks(void);
-extern int cr_show(int pid);
 extern int convert_to_elf(char *elf_path, int fd_core);
 extern int cr_check(void);
 extern int cr_exec(int pid, char **opts);
diff --git a/include/namespaces.h b/include/namespaces.h
index 4ce5a34..eba0fac 100644
--- a/include/namespaces.h
+++ b/include/namespaces.h
@@ -75,7 +75,6 @@ extern int dump_mnt_namespaces(void);
 extern int dump_namespaces(struct pstree_item *item, unsigned int ns_flags);
 extern int prepare_namespace_before_tasks(void);
 extern int prepare_namespace(struct pstree_item *item, unsigned long clone_flags);
-extern int try_show_namespaces(int pid);
 
 extern int switch_ns(int pid, struct ns_desc *nd, int *rst);
 extern int restore_ns(int rst, struct ns_desc *nd);
diff --git a/include/protobuf.h b/include/protobuf.h
index 3d76b13..1b22767 100644
--- a/include/protobuf.h
+++ b/include/protobuf.h
@@ -27,20 +27,6 @@ extern int pb_write_one(struct cr_img *, void *obj, int type);
 
 #include <google/protobuf-c/protobuf-c.h>
 
-extern void do_pb_show_plain(struct cr_img *, int type, int single_entry,
-		void (*payload_hadler)(struct cr_img *, void *obj),
-		const char *pretty_fmt);
-
-/* Don't have objects at hands to also do typechecking here */
-#define pb_show_plain_payload_pretty(__fd, __type, payload_hadler, pretty)	\
-	do_pb_show_plain(__fd, __type, 0, payload_hadler, pretty)
-
-#define pb_show_plain_payload(__fd, __proto_message_name, payload_hadler)	\
-	pb_show_plain_payload_pretty(__fd, __proto_message_name, payload_hadler, NULL)
-
-#define pb_show_plain_pretty(__fd, __proto_message_name, __pretty)		\
-	pb_show_plain_payload_pretty(__fd, __proto_message_name, NULL, __pretty)
-
 struct collect_image_info {
 	int fd_type;
 	int pb_type;
diff --git a/include/util.h b/include/util.h
index a647827..befb70d 100644
--- a/include/util.h
+++ b/include/util.h
@@ -281,4 +281,6 @@ char *xstrcat(char *str, const char *fmt, ...)
 char *xsprintf(const char *fmt, ...)
 	__attribute__ ((__format__ (__printf__, 1, 2)));
 
+void print_data(unsigned long addr, unsigned char *data, size_t size);
+
 #endif /* __CR_UTIL_H__ */
diff --git a/ipc_ns.c b/ipc_ns.c
index 9abb403..b5356b9 100644
--- a/ipc_ns.c
+++ b/ipc_ns.c
@@ -62,7 +62,6 @@ static void pr_ipc_sem_array(unsigned int loglevel, int nr, u16 *values)
 }
 
 #define pr_info_ipc_sem_array(nr, values)	pr_ipc_sem_array(LOG_INFO, nr, values)
-#define pr_msg_ipc_sem_array(nr, values)	pr_ipc_sem_array(LOG_MSG, nr, values)
 
 static void pr_info_ipc_sem_entry(const IpcSemEntry *sem)
 {
@@ -473,48 +472,6 @@ err:
 	return ret < 0 ? -1 : 0;
 }
 
-void ipc_sem_handler(struct cr_img *img, void *obj)
-{
-	IpcSemEntry *e = obj;
-	u16 *values;
-	int size;
-
-	pr_msg("\n");
-	size = round_up(sizeof(u16) * e->nsems, sizeof(u64));
-	values = xmalloc(size);
-	if (values == NULL)
-		return;
-	if (read_img_buf(img, values, size) <= 0) {
-		xfree(values);
-		return;
-	}
-	pr_msg_ipc_sem_array(e->nsems, values);
-	xfree(values);
-}
-
-static void ipc_msg_data_handler(struct cr_img *img, void *obj)
-{
-	IpcMsg *e = obj;
-	print_image_data(img, round_up(e->msize, sizeof(u64)), opts.show_pages_content);
-}
-
-void ipc_msg_handler(struct cr_img *img, void *obj)
-{
-	IpcMsgEntry *e = obj;
-	int msg_nr = 0;
-
-	pr_msg("\n");
-	while (msg_nr++ < e->qnum)
-		pb_show_plain_payload(img, PB_IPCNS_MSG, ipc_msg_data_handler);
-
-}
-
-void ipc_shm_handler(struct cr_img *img, void *obj)
-{
-	IpcShmEntry *e = obj;
-	print_image_data(img, round_up(e->size, sizeof(u32)), opts.show_pages_content);
-}
-
 static int prepare_ipc_sem_values(struct cr_img *img, const IpcSemEntry *sem)
 {
 	int ret, size;
diff --git a/namespaces.c b/namespaces.c
index 9a7836b..42a5373 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -10,7 +10,6 @@
 #include <signal.h>
 #include <sched.h>
 
-#include "cr-show.h"
 #include "util.h"
 #include "imgset.h"
 #include "uts_ns.h"
@@ -1338,66 +1337,5 @@ err_unds:
 	return -1;
 }
 
-int try_show_namespaces(int ns_pid)
-{
-	struct cr_imgset *imgset;
-	int i, ret;
-	struct cr_img *img;
-	TaskKobjIdsEntry *ids;
-
-	pr_msg("Namespaces for %d:\n", ns_pid);
-
-	img = open_image(CR_FD_IDS, O_RSTR, ns_pid);
-	if (!img)
-		return -1;
-	ret = pb_read_one(img, &ids, PB_IDS);
-	close_image(img);
-	if (ret < 0)
-		return -1;
-
-	imgset = cr_imgset_open(ids->net_ns_id, NETNS, O_SHOW);
-	if (imgset) {
-		pr_msg("-------------------NETNS---------------------\n");
-		for (i = _CR_FD_NETNS_FROM + 1; i < _CR_FD_NETNS_TO; i++) {
-			img = img_from_set(imgset, i);
-			if (!img)
-				continue;
-
-			cr_parse_fd(img, imgset_template[i].magic);
-		}
-		close_cr_imgset(&imgset);
-	}
-
-	imgset = cr_imgset_open(ids->ipc_ns_id, IPCNS, O_SHOW);
-	if (imgset) {
-		pr_msg("-------------------IPCNS---------------------\n");
-		for (i = _CR_FD_IPCNS_FROM + 1; i < _CR_FD_IPCNS_TO; i++) {
-			img = img_from_set(imgset, i);
-			if (!img)
-				continue;
-
-			cr_parse_fd(img, imgset_template[i].magic);
-		}
-		close_cr_imgset(&imgset);
-	}
-
-	img = open_image(CR_FD_UTSNS, O_SHOW, ids->uts_ns_id);
-	if (img) {
-		pr_msg("-------------------UTSNS---------------------\n");
-		cr_parse_fd(img, imgset_template[CR_FD_UTSNS].magic);
-		close_image(img);
-	}
-
-	img = open_image(CR_FD_MNTS, O_SHOW, ids->mnt_ns_id);
-	if (img) {
-		pr_msg("-------------------MNTNS---------------------\n");
-		cr_parse_fd(img, imgset_template[CR_FD_MNTS].magic);
-		close_image(img);
-	}
-
-	pr_msg("---[ end of %d namespaces ]---\n", ns_pid);
-	return 0;
-}
-
 struct ns_desc pid_ns_desc = NS_DESC_ENTRY(CLONE_NEWPID, "pid");
 struct ns_desc user_ns_desc = NS_DESC_ENTRY(CLONE_NEWUSER, "user");
diff --git a/protobuf.c b/protobuf.c
index ae003da..3201ad4 100644
--- a/protobuf.c
+++ b/protobuf.c
@@ -27,471 +27,6 @@
  */
 #define PB_PKOBJ_LOCAL_SIZE	1024
 
-#define INET_ADDR_LEN		40
-
-typedef struct {
-	void		*data;
-	int		number;
-	int		depth;
-	int		count;
-	char		fmt[32];
-} pb_pr_field_t;
-
-typedef struct {
-	void		*arg;
-	int		single_entry;
-	const char	*pretty_fmt;
-	pb_pr_field_t	cur;
-} pb_pr_ctl_t;
-
-typedef int (*pb_pr_show_t)(pb_pr_field_t *field);
-
-/*
- * This one describes how fields should be shown
- * @fsize is the size of the field entry
- * @show is the callback to print the entry
- */
-struct pb_shower {
-	size_t fsize;
-	pb_pr_show_t show;
-};
-
-static int pb_msg_int32x(pb_pr_field_t *field)
-{
-	pr_msg("%#x", *(int *)field->data);
-	return 0;
-}
-
-static int pb_msg_int64x(pb_pr_field_t *field)
-{
-	pr_msg("%#016lx", *(long *)field->data);
-	return 0;
-}
-
-static int pb_msg_int64x_r(pb_pr_field_t *field)
-{
-	long val = *(long *)field->data;
-	if (val)
-		pr_msg("%#016lx", val);
-	else
-		pr_msg("0");
-	return 0;
-}
-
-static int pb_msg_string(pb_pr_field_t *field)
-{
-	pr_msg("\"%s\"",	*(char **)field->data);
-	return 0;
-}
-
-static int pb_msg_unk(pb_pr_field_t *field)
-{
-	pr_msg("unknown object %p", field->data);
-	return 0;
-}
-
-static inline void print_tabs(pb_pr_ctl_t *ctl)
-{
-	int counter = ctl->cur.depth;
-
-	if (!ctl->single_entry)
-		return;
-
-	while (counter--)
-		pr_msg("\t");
-}
-
-static void print_nested_message_braces(pb_pr_ctl_t *ctl, int right_brace)
-{
-	print_tabs(ctl);
-	pr_msg("%s%s", (right_brace) ? "}" : "{", (ctl->single_entry) ? "\n" : " ");
-}
-
-static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl);
-
-static int show_nested_message(pb_pr_field_t *field)
-{
-	pb_pr_ctl_t *ctl = container_of(field, pb_pr_ctl_t, cur);
-	void *arg = ctl->arg;
-
-	print_nested_message_braces(ctl, 0);
-	field->depth++;
-	pb_show_msg(field->data, ctl);
-	field->depth--;
-	print_nested_message_braces(ctl, 1);
-	ctl->arg = arg;
-	return 0;
-}
-
-static int show_enum(pb_pr_field_t *field)
-{
-	pb_pr_ctl_t *ctl = container_of(field, pb_pr_ctl_t, cur);
-	ProtobufCEnumDescriptor *d = ctl->arg;
-	const char *val_name = NULL;
-	int val, i;
-
-	val = *(int *)field->data;
-	for (i = 0; i < d->n_values; i++)
-		if (d->values[i].value == val) {
-			val_name = d->values[i].name;
-			break;
-		}
-
-	if (val_name != NULL)
-		pr_msg("%s", val_name);
-	else
-		pr_msg("%d", val);
-	return 0;
-}
-
-static int show_bool(pb_pr_field_t *field)
-{
-	protobuf_c_boolean val = *(protobuf_c_boolean *)field->data;
-
-	if (val)
-		pr_msg("True");
-	else
-		pr_msg("False");
-	return 0;
-}
-
-static int show_bytes(pb_pr_field_t *field)
-{
-	ProtobufCBinaryData *bytes = (ProtobufCBinaryData *)field->data;
-	int i = 0;
-
-	while (i < bytes->len)
-		pr_msg("%02x ", bytes->data[i++]);
-	return 0;
-}
-
-static int pb_show_pretty(pb_pr_field_t *field)
-{
-	switch (field->fmt[0]) {
-	case '%':
-		pr_msg(field->fmt, *(long *)field->data);
-		break;
-	case 'S':
-		{
-			ProtobufCBinaryData *name = (ProtobufCBinaryData *)field->data;
-			int i;
-
-			for (i = 0; i < name->len; i++) {
-				char c = (char)name->data[i];
-
-				if (isprint(c))
-					pr_msg("%c", c);
-				else if (c != 0)
-					pr_msg(".");
-			}
-			break;
-		}
-	case 'A':
-		{
-			char addr[INET_ADDR_LEN] = "<unknown>";
-			int family = (field->count == 1) ? AF_INET : AF_INET6;
-
-			if (inet_ntop(family, (void *)field->data, addr,
-				      INET_ADDR_LEN) == NULL)
-				pr_msg("failed to translate");
-			else
-				pr_msg("%s", addr);
-		}
-		return 1;
-	}
-	return 0;
-}
-
-static void pb_copy_fmt(const char *fmt, char *to)
-{
-	while (*fmt != ' ' && *fmt != '\0') {
-		*to = *fmt;
-		to++;
-		fmt++;
-	}
-
-	*to = '\0';
-}
-
-static const char *pb_next_pretty(const char *pfmt)
-{
-	pfmt = strchr(pfmt, ' ');
-	if (pfmt) {
-		while (*pfmt == ' ')
-			pfmt++;
-
-		if (*pfmt == '\0')
-			pfmt = NULL;
-	}
-
-	return pfmt;
-}
-
-static int pb_find_fmt(char *what, pb_pr_ctl_t *ctl)
-{
-	int len;
-	const char *pretty = ctl->pretty_fmt;
-
-	len = strlen(what);
-	while (1) {
-		if (!strncmp(pretty, what, len)) {
-			pb_copy_fmt(pretty + len, ctl->cur.fmt);
-			return 1;
-		}
-
-		pretty = pb_next_pretty(pretty + len);
-		if (!pretty)
-			return 0;
-	}
-}
-
-static int pb_field_show_pretty(const ProtobufCFieldDescriptor *fd, pb_pr_ctl_t *ctl)
-{
-	char cookie[32];
-
-	if (!ctl->pretty_fmt)
-		return 0;
-
-	sprintf(cookie, "%s:", fd->name);
-	if (pb_find_fmt(cookie, ctl))
-		return 1;
-
-	if (!ctl->cur.depth)
-		sprintf(cookie, "%d:", ctl->cur.number);
-	else
-		sprintf(cookie, "%d.%d:", ctl->cur.depth, ctl->cur.number);
-
-	if (pb_find_fmt(cookie, ctl))
-		return 1;
-
-	sprintf(cookie, "*:");
-	if (pb_find_fmt(cookie, ctl))
-		return 1;
-
-	return 0;
-}
-
-static void pb_prepare_shower(const ProtobufCFieldDescriptor *fd,
-		pb_pr_ctl_t *ctl, struct pb_shower *sh)
-{
-	sh->fsize = 0;
-	sh->show = pb_msg_unk;
-
-	switch (fd->type) {
-	case PROTOBUF_C_TYPE_INT32:
-	case PROTOBUF_C_TYPE_SINT32:
-	case PROTOBUF_C_TYPE_UINT32:
-	case PROTOBUF_C_TYPE_SFIXED32:
-		sh->fsize = 4;
-		sh->show = pb_msg_int32x;
-		break;
-
-	case PROTOBUF_C_TYPE_INT64:
-	case PROTOBUF_C_TYPE_SINT64:
-	case PROTOBUF_C_TYPE_SFIXED64:
-	case PROTOBUF_C_TYPE_FIXED32:
-	case PROTOBUF_C_TYPE_UINT64:
-	case PROTOBUF_C_TYPE_FIXED64:
-		sh->fsize = 8;
-		sh->show = (fd->label == PROTOBUF_C_LABEL_REPEATED ?
-				pb_msg_int64x_r : pb_msg_int64x);
-		break;
-
-	case PROTOBUF_C_TYPE_STRING:
-		sh->fsize = sizeof (void *);
-		sh->show = pb_msg_string;
-		break;
-	case PROTOBUF_C_TYPE_MESSAGE:
-		sh->fsize = sizeof (void *);
-		sh->show = show_nested_message;
-		ctl->arg = (void *)fd->descriptor;
-		break;
-	case PROTOBUF_C_TYPE_ENUM:
-		sh->fsize = 4;
-		sh->show = show_enum;
-		ctl->arg = (void *)fd->descriptor;
-		break;
-
-	case PROTOBUF_C_TYPE_BOOL:
-		sh->fsize = sizeof (protobuf_c_boolean);
-		sh->show = show_bool;
-		break;
-	case PROTOBUF_C_TYPE_BYTES:
-		sh->fsize = sizeof (ProtobufCBinaryData);
-		sh->show = show_bytes;
-		break;
-	case PROTOBUF_C_TYPE_FLOAT:
-		sh->fsize = 4;
-		break;
-	case PROTOBUF_C_TYPE_DOUBLE:
-		sh->fsize = 8;
-		break;
-
-	default:
-		BUG();
-	}
-
-	if (pb_field_show_pretty(fd, ctl))
-		sh->show = pb_show_pretty;
-}
-
-static void pb_show_repeated(const ProtobufCFieldDescriptor *fd,
-		pb_pr_ctl_t *ctl, struct pb_shower *sh)
-{
-	pb_pr_field_t *field = &ctl->cur;
-	unsigned long i, nr_fields = field->count;
-
-	if (nr_fields == 0) {
-		pr_msg("<empty>");
-		return;
-	}
-
-	if (fd->type == PROTOBUF_C_TYPE_MESSAGE) {
-		void *p = field->data;
-
-		for (i = 0; i < nr_fields; i++) {
-			field->data = (void *)(*(long *)p);
-			sh->show(field);
-			p += sh->fsize;
-		}
-
-		return;
-	}
-
-	for (i = 0; i < nr_fields; i++) {
-		if (i)
-			pr_msg(":");
-		if (sh->show(field))
-			break;
-		field->data += sh->fsize;
-	}
-}
-
-static void pb_show_field(const ProtobufCFieldDescriptor *fd, pb_pr_ctl_t *ctl)
-{
-	struct pb_shower sh;
-
-	print_tabs(ctl);
-	pr_msg("%s: ", fd->name);
-
-	pb_prepare_shower(fd, ctl, &sh);
-	pb_show_repeated(fd, ctl, &sh);
-
-	if (ctl->single_entry)
-		pr_msg("\n");
-	else
-		pr_msg(" ");
-}
-
-static int pb_optional_field_present(const ProtobufCFieldDescriptor *field,
-		const void *msg)
-{
-	if ((field->type == PROTOBUF_C_TYPE_MESSAGE) ||
-		(field->type == PROTOBUF_C_TYPE_STRING)) {
-		const void *opt_flag = * (const void * const *)(msg + field->offset);
-
-		if ((opt_flag == NULL) || (opt_flag == field->default_value))
-			return 0;
-	} else {
-		const protobuf_c_boolean *has = msg + field->quantifier_offset;
-
-		if (!*has)
-			return 0;
-	}
-	return 1;
-}
-
-static bool should_show_field(const char *name)
-{
-	char *s, *e;
-	int len;
-
-	if (!opts.show_fmt)
-		return true;
-
-	len = strlen(name);
-	s = opts.show_fmt;
-
-	while (1) {
-		e = strchrnul(s, ',');
-		if (e - s == len) {
-			if (!strncmp(name, s, len))
-				return true;
-		}
-		if (*e == '\0')
-			return false;
-		s = e + 1;
-	}
-}
-
-static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl)
-{
-	int i;
-	const ProtobufCMessageDescriptor *md = ctl->arg;
-
-	BUG_ON(md == NULL);
-
-	for (i = 0; i < md->n_fields; i++) {
-		const ProtobufCFieldDescriptor fd = md->fields[i];
-		unsigned long *data;
-		size_t nr_fields;
-
-		nr_fields = 1;
-		data = (unsigned long *)(msg + fd.offset);
-
-		if (fd.label == PROTOBUF_C_LABEL_OPTIONAL) {
-			if (!pb_optional_field_present(&fd, msg))
-				continue;
-		}
-
-		if (!should_show_field(fd.name))
-			continue;
-
-		if (fd.label == PROTOBUF_C_LABEL_REPEATED) {
-			nr_fields = *(size_t *)(msg + fd.quantifier_offset);
-			data = (unsigned long *)*data;
-		}
-
-		ctl->cur.data = data;
-		ctl->cur.number = i + 1;
-		ctl->cur.count = nr_fields;
-
-		pb_show_field(&fd, ctl);
-	}
-}
-
-static inline void pb_no_payload(struct cr_img *i, void *obj) { }
-
-void do_pb_show_plain(struct cr_img *img, int type, int single_entry,
-		void (*payload_hadler)(struct cr_img *, void *obj),
-		const char *pretty_fmt)
-{
-	pb_pr_ctl_t ctl = {NULL, single_entry, pretty_fmt};
-	void (*handle_payload)(struct cr_img *, void *obj);
-
-	if (!cr_pb_descs[type].pb_desc) {
-		pr_err("Wrong object requested %d\n", type);
-		return;
-	}
-
-	handle_payload = (payload_hadler) ? : pb_no_payload;
-
-	while (1) {
-		void *obj;
-
-		if (pb_read_one_eof(img, &obj, type) <= 0)
-			break;
-
-		ctl.arg = (void *)cr_pb_descs[type].pb_desc;
-		pb_show_msg(obj, &ctl);
-		handle_payload(img, obj);
-		cr_pb_descs[type].free(obj, NULL);
-		if (single_entry)
-			break;
-		pr_msg("\n");
-	}
-}
-
 static char *image_name(struct cr_img *img)
 {
 	int fd = img->_x.fd;
diff --git a/sk-queue.c b/sk-queue.c
index 6a39c4b..1f19aa0 100644
--- a/sk-queue.c
+++ b/sk-queue.c
@@ -179,12 +179,6 @@ err_brk:
 	return ret;
 }
 
-void sk_queue_data_handler(struct cr_img *img, void *obj)
-{
-	SkPacketEntry *e = obj;
-	print_image_data(img, e->length, opts.show_pages_content);
-}
-
 int restore_sk_queue(int fd, unsigned int peer_id)
 {
 	struct sk_packet *pkt, *tmp;
diff --git a/sk-tcp.c b/sk-tcp.c
index 8e17024..83dd0e2 100644
--- a/sk-tcp.c
+++ b/sk-tcp.c
@@ -21,7 +21,6 @@
 #include "namespaces.h"
 #include "xmalloc.h"
 #include "config.h"
-#include "cr-show.h"
 #include "kerndat.h"
 #include "rst-malloc.h"
 
@@ -758,14 +757,3 @@ out:
 
 	return ret;
 }
-
-void show_tcp_stream(struct cr_img *img, void *obj)
-{
-	TcpStreamEntry *e = obj;
-	if (opts.show_pages_content) {
-		pr_msg("In-queue:");
-		print_image_data(img, e->inq_len, 1);
-		pr_msg("Out-queue:");
-		print_image_data(img, e->outq_len, 1);
-	}
-}
diff --git a/tun.c b/tun.c
index dcee704..4eb88ad 100644
--- a/tun.c
+++ b/tun.c
@@ -11,7 +11,6 @@
 #include "cr_options.h"
 #include "imgset.h"
 #include "protobuf.h"
-#include "cr-show.h"
 #include "string.h"
 #include "files.h"
 #include "files-reg.h"
diff --git a/util.c b/util.c
index 00c3273..cbc525d 100644
--- a/util.c
+++ b/util.c
@@ -32,6 +32,7 @@
 #include <netinet/in.h>
 #include <netinet/tcp.h>
 #include <sched.h>
+#include <ctype.h>
 
 #include "compiler.h"
 #include "asm/types.h"
@@ -42,6 +43,7 @@
 #include "vma.h"
 #include "mem.h"
 #include "namespaces.h"
+#include "log.h"
 
 #include "cr_options.h"
 #include "servicefd.h"
@@ -1000,3 +1002,75 @@ void tcp_nodelay(int sk, bool on)
 	int val = on ? 1 : 0;
 	setsockopt(sk, SOL_TCP, TCP_NODELAY, &val, sizeof(val));
 }
+
+static inline void pr_xsym(unsigned char *data, size_t len, int pos)
+{
+	char sym;
+
+	if (pos < len)
+		sym = data[pos];
+	else
+		sym = ' ';
+
+	pr_msg("%c", isprint(sym) ? sym : '.');
+}
+
+static inline void pr_xdigi(unsigned char *data, size_t len, int pos)
+{
+	if (pos < len)
+		pr_msg("%02x ", data[pos]);
+	else
+		pr_msg("   ");
+}
+
+static int nice_width_for(unsigned long addr)
+{
+	int ret = 3;
+
+	while (addr) {
+		addr >>= 4;
+		ret++;
+	}
+
+	return ret;
+}
+
+void print_data(unsigned long addr, unsigned char *data, size_t size)
+{
+	int i, j, addr_len;
+	unsigned zero_line = 0;
+
+	addr_len = nice_width_for(addr + size);
+
+	for (i = 0; i < size; i += 16) {
+		if (*(u64 *)(data + i) == 0 && *(u64 *)(data + i + 8) == 0) {
+			if (zero_line == 0)
+				zero_line = 1;
+			else {
+				if (zero_line == 1) {
+					pr_msg("*\n");
+					zero_line = 2;
+				}
+
+				continue;
+			}
+		} else
+			zero_line = 0;
+
+		pr_msg("%#0*lx: ", addr_len, addr + i);
+		for (j = 0; j < 8; j++)
+			pr_xdigi(data, size, i + j);
+		pr_msg(" ");
+		for (j = 8; j < 16; j++)
+			pr_xdigi(data, size, i + j);
+
+		pr_msg(" |");
+		for (j = 0; j < 8; j++)
+			pr_xsym(data, size, i + j);
+		pr_msg(" ");
+		for (j = 8; j < 16; j++)
+			pr_xsym(data, size, i + j);
+
+		pr_msg("|\n");
+	}
+}
-- 
2.1.4


More information about the CRIU mailing list