mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-03 15:55:53 +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:
@@ -40,6 +40,7 @@ struct collect_image_info {
|
|||||||
#define COLLECT_HAPPENED 0x4 /* image was opened and collected */
|
#define COLLECT_HAPPENED 0x4 /* image was opened and collected */
|
||||||
|
|
||||||
extern int collect_image(struct collect_image_info *);
|
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)
|
static inline int collect_images(struct collect_image_info **array, unsigned size)
|
||||||
{
|
{
|
||||||
|
@@ -172,6 +172,37 @@ err:
|
|||||||
return ret;
|
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 collect_image(struct collect_image_info *cinfo)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
Reference in New Issue
Block a user