2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 06:15:24 +00:00

pb: Add a helper to collect single entry

Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
Pavel Emelyanov
2017-06-30 13:56:49 +03:00
parent 41df032e12
commit b7b3b19f7e
2 changed files with 32 additions and 0 deletions

View File

@@ -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)
{

View File

@@ -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;