[CRIU] [PATCH 04/22] pb: Add a helper to collect single entry

Pavel Emelyanov xemul at virtuozzo.com
Fri Jun 30 13:56:49 MSK 2017


Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/include/protobuf.h |  1 +
 criu/protobuf.c         | 31 +++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/criu/include/protobuf.h b/criu/include/protobuf.h
index 6097ba0..fb7489e 100644
--- a/criu/include/protobuf.h
+++ b/criu/include/protobuf.h
@@ -40,6 +40,7 @@ struct collect_image_info {
 #define COLLECT_HAPPENED	0x4	/* image was opened and collected */
 
 extern int collect_image(struct collect_image_info *);
+extern int collect_entry(ProtobufCMessage *base, struct collect_image_info *cinfo);
 
 static inline int collect_images(struct collect_image_info **array, unsigned size)
 {
diff --git a/criu/protobuf.c b/criu/protobuf.c
index 219c7c0..8eb73e0 100644
--- a/criu/protobuf.c
+++ b/criu/protobuf.c
@@ -172,6 +172,37 @@ err:
 	return ret;
 }
 
+int collect_entry(ProtobufCMessage *msg, struct collect_image_info *cinfo)
+{
+	void *obj;
+	void *(*o_alloc)(size_t size) = malloc;
+	void (*o_free)(void *ptr) = free;
+
+	if (cinfo->flags & COLLECT_SHARED) {
+		o_alloc = shmalloc;
+		o_free = shfree_last;
+	}
+
+	if (cinfo->priv_size) {
+		obj = o_alloc(cinfo->priv_size);
+		if (!obj)
+			return -1;
+	} else
+		obj = NULL;
+
+	cinfo->flags |= COLLECT_HAPPENED;
+	if (cinfo->collect(obj, msg, NULL) < 0) {
+		o_free(obj);
+		cr_pb_descs[cinfo->pb_type].free(msg, NULL);
+		return -1;
+	}
+
+	if (!cinfo->priv_size && !(cinfo->flags & COLLECT_NOFREE))
+		cr_pb_descs[cinfo->pb_type].free(msg, NULL);
+
+	return 0;
+}
+
 int collect_image(struct collect_image_info *cinfo)
 {
 	int ret;
-- 
2.1.4



More information about the CRIU mailing list