diff --git a/cr-dump.c b/cr-dump.c index 8d8acb8bb..4f49e1409 100644 --- a/cr-dump.c +++ b/cr-dump.c @@ -1575,7 +1575,6 @@ static int cr_dump_finish(int ret) close_service_fd(CR_PROC_FD_OFF); if (ret) { - kill_inventory(); pr_err("Dumping FAILED.\n"); } else { write_stats(DUMP_STATS); @@ -1593,6 +1592,7 @@ void dump_alarm_handler(int signum) int cr_dump_tasks(pid_t pid) { + InventoryEntry he = INVENTORY_ENTRY__INIT; struct pstree_item *item; int pre_dump_ret = 0; int ret = -1; @@ -1627,7 +1627,7 @@ int cr_dump_tasks(pid_t pid) if (parse_cg_info()) goto err; - if (write_img_inventory()) + if (prepare_inventory(&he)) goto err; if (opts.cpu_cap & (CPU_CAP_CPU | CPU_CAP_INS)) { @@ -1710,6 +1710,9 @@ int cr_dump_tasks(pid_t pid) if (ret) goto err; + ret = write_img_inventory(&he); + if (ret) + goto err; err: return cr_dump_finish(ret); } diff --git a/image.c b/image.c index dc9d6a189..a164722bb 100644 --- a/image.c +++ b/image.c @@ -77,14 +77,9 @@ out_close: return ret; } -int write_img_inventory(void) +int write_img_inventory(InventoryEntry *he) { struct cr_img *img; - InventoryEntry he = INVENTORY_ENTRY__INIT; - struct { - struct pstree_item i; - struct dmp_info d; - } crt = { }; pr_info("Writing image inventory (version %u)\n", CRTOOLS_IMAGES_V1); @@ -92,38 +87,42 @@ int write_img_inventory(void) if (!img) return -1; - he.img_version = CRTOOLS_IMAGES_V1_1; - he.fdinfo_per_id = true; - he.has_fdinfo_per_id = true; - he.ns_per_id = true; - he.has_ns_per_id = true; - he.lsmtype = host_lsm_type(); - - crt.i.state = TASK_ALIVE; - crt.i.pid.real = getpid(); - if (get_task_ids(&crt.i)) { - close_image(img); - return -1; - } - - he.has_root_cg_set = true; - if (dump_task_cgroup(NULL, &he.root_cg_set)) + if (pb_write_one(img, he, PB_INVENTORY) < 0) return -1; - he.root_ids = crt.i.ids; - - if (pb_write_one(img, &he, PB_INVENTORY) < 0) - return -1; - - xfree(crt.i.ids); + xfree(he->root_ids); close_image(img); return 0; } -void kill_inventory(void) +int prepare_inventory(InventoryEntry *he) { - unlinkat(get_service_fd(IMG_FD_OFF), - imgset_template[CR_FD_INVENTORY].fmt, 0); + struct { + struct pstree_item i; + struct dmp_info d; + } crt = { }; + + pr_info("Perparing image inventory (version %u)\n", CRTOOLS_IMAGES_V1); + + he->img_version = CRTOOLS_IMAGES_V1_1; + he->fdinfo_per_id = true; + he->has_fdinfo_per_id = true; + he->ns_per_id = true; + he->has_ns_per_id = true; + he->lsmtype = host_lsm_type(); + + crt.i.state = TASK_ALIVE; + crt.i.pid.real = getpid(); + if (get_task_ids(&crt.i)) + return -1; + + he->has_root_cg_set = true; + if (dump_task_cgroup(NULL, &he->root_cg_set)) + return -1; + + he->root_ids = crt.i.ids; + + return 0; } static struct cr_imgset *alloc_cr_imgset(int nr) diff --git a/include/crtools.h b/include/crtools.h index bbed0effd..eaa70dcf4 100644 --- a/include/crtools.h +++ b/include/crtools.h @@ -7,11 +7,14 @@ #include "asm/types.h" #include "servicefd.h" +#include "protobuf.h" +#include "protobuf/inventory.pb-c.h" + #define CR_FD_PERM (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) extern int check_img_inventory(void); -extern int write_img_inventory(void); -extern void kill_inventory(void); +extern int write_img_inventory(InventoryEntry *he); +extern int prepare_inventory(InventoryEntry *he); #define LAST_PID_PATH "sys/kernel/ns_last_pid"