[CRIU] [PATCH 2/5] protobuf: vertical output support introduced

Kinsbursky Stanislav skinsbursky at openvz.org
Tue Jul 24 09:59:12 EDT 2012


Will be used for single-entry images.

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

---
 include/protobuf.h |    9 +++++++--
 protobuf.c         |   23 +++++++++++++++++------
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/include/protobuf.h b/include/protobuf.h
index 2818ae4..5edb7cb 100644
--- a/include/protobuf.h
+++ b/include/protobuf.h
@@ -59,12 +59,17 @@ extern int pb_write_object_with_header(int fd, void *obj,
 #include <google/protobuf-c/protobuf-c.h>
 
 extern void do_pb_show_plain(int fd, const ProtobufCMessageDescriptor *d,
-		pb_unpack_t unpack, pb_free_t free);
+		pb_unpack_t unpack, pb_free_t free, int single_entry);
 
 /* Don't have objects at hands to also do typechecking here */
 #define pb_show_plain(__fd, __proto_message_name)			\
 	do_pb_show_plain(__fd, &__proto_message_name##__descriptor,	\
 			(pb_unpack_t)__proto_message_name##__unpack,			\
-			(pb_free_t)__proto_message_name##__free_unpacked)
+			(pb_free_t)__proto_message_name##__free_unpacked, 0)
+
+#define pb_show_vertical(__fd, __proto_message_name)			\
+	do_pb_show_plain(__fd, &__proto_message_name##__descriptor,	\
+			(pb_unpack_t)__proto_message_name##__unpack,			\
+			(pb_free_t)__proto_message_name##__free_unpacked, 1)
 
 #endif /* PROTOBUF_H__ */
diff --git a/protobuf.c b/protobuf.c
index 4d84a13..a0a48b5 100644
--- a/protobuf.c
+++ b/protobuf.c
@@ -22,6 +22,7 @@
 
 struct pb_pr_ctrl_s {
 	void *arg;
+	int single_entry;
 };
 
 typedef struct pb_pr_ctrl_s pb_pr_ctl_t;
@@ -47,13 +48,18 @@ static void pb_msg_unk(void *obj, pb_pr_ctl_t *ctl)
 	pr_msg("unknown object %p\n", obj);
 }
 
+static void print_nested_message_braces(pb_pr_ctl_t *ctl, int side)
+{
+	pr_msg("%s%s", (side) ? "]" : "[", (ctl->single_entry) ? "\n" : " ");
+}
+
 static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl);
 
 static void show_nested_message(void *msg, pb_pr_ctl_t *ctl)
 {
-	pr_msg("[ ");
+	print_nested_message_braces(ctl, 0);
 	pb_show_msg(msg, ctl);
-	pr_msg(" ] ");
+	print_nested_message_braces(ctl, 1);
 }
 
 static void show_enum(void *msg, pb_pr_ctl_t *ctl)
@@ -133,7 +139,10 @@ static void pb_show_field(const ProtobufCFieldDescriptor *fd, void *where,
 		show(where, ctl);
 	}
 
-	pr_msg(" ");
+	if (ctl->single_entry)
+		pr_msg("\n");
+	else
+		pr_msg(" ");
 }
 
 static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl)
@@ -164,9 +173,9 @@ static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl)
 }
 
 void do_pb_show_plain(int fd, const ProtobufCMessageDescriptor *md,
-		pb_unpack_t unpack, pb_free_t free)
+		pb_unpack_t unpack, pb_free_t free, int single_entry)
 {
-	pb_pr_ctl_t ctl = {NULL};
+	pb_pr_ctl_t ctl = {NULL, single_entry};
 
 	while (1) {
 		void *obj;
@@ -176,8 +185,10 @@ void do_pb_show_plain(int fd, const ProtobufCMessageDescriptor *md,
 
 		ctl.arg = (void *)md;
 		pb_show_msg(obj, &ctl);
-		pr_msg("\n");
 		free(obj, NULL);
+		if (single_entry)
+			break;
+		pr_msg("\n");
 	}
 }
 



More information about the CRIU mailing list