diff --git a/cr-show.c b/cr-show.c index 5404b7d5c..9ce27c6a1 100644 --- a/cr-show.c +++ b/cr-show.c @@ -27,6 +27,7 @@ #include "protobuf.h" #include "protobuf/fdinfo.pb-c.h" #include "protobuf/regfile.pb-c.h" +#include "protobuf/ghost-file.pb-c.h" #define DEF_PAGES_PER_LINE 6 @@ -157,11 +158,13 @@ void show_remap_files(int fd, struct cr_options *o) void show_ghost_file(int fd, struct cr_options *o) { - struct ghost_file_entry gfe; + GhostFileEntry *gfe; pr_img_head(CR_FD_GHOST_FILE); - if (read_img(fd, &gfe) > 0) - pr_msg("uid %u god %u mode %#x\n", gfe.uid, gfe.gid, gfe.mode); + if (pb_read_eof(fd, &gfe, ghost_file_entry) > 0) { + pr_msg("uid %u god %u mode %#x\n", gfe->uid, gfe->gid, gfe->mode); + ghost_file_entry__free_unpacked(gfe, NULL); + } pr_img_tail(CR_FD_GHOST_FILE); } diff --git a/files-reg.c b/files-reg.c index 3f15a2a98..a03a456b5 100644 --- a/files-reg.c +++ b/files-reg.c @@ -60,7 +60,7 @@ static int open_remap_ghost(struct reg_file_info *rfi, struct remap_file_path_entry *rfe) { struct ghost_file *gf; - struct ghost_file_entry gfe; + GhostFileEntry *gfe = NULL; int gfd, ifd, ghost_flags; list_for_each_entry(gf, &ghost_files, list) @@ -86,13 +86,13 @@ static int open_remap_ghost(struct reg_file_info *rfi, if (ifd < 0) goto err; - if (read_img(ifd, &gfe) < 0) + if (pb_read(ifd, &gfe, ghost_file_entry) < 0) goto err; snprintf(gf->path, PATH_MAX, "%s.cr.%x.ghost", rfi->path, rfe->remap_id); - if (S_ISFIFO(gfe.mode)) { - if (mknod(gf->path, gfe.mode, 0)) { + if (S_ISFIFO(gfe->mode)) { + if (mknod(gf->path, gfe->mode, 0)) { pr_perror("Can't create node for ghost file\n"); goto err; } @@ -100,22 +100,23 @@ static int open_remap_ghost(struct reg_file_info *rfi, } else ghost_flags = O_WRONLY | O_CREAT | O_EXCL; - gfd = open(gf->path, ghost_flags, gfe.mode); + gfd = open(gf->path, ghost_flags, gfe->mode); if (gfd < 0) { pr_perror("Can't open ghost file"); goto err; } - if (fchown(gfd, gfe.uid, gfe.gid) < 0) { + if (fchown(gfd, gfe->uid, gfe->gid) < 0) { pr_perror("Can't reset user/group on ghost %#x\n", rfe->remap_id); goto err; } - if (S_ISREG(gfe.mode)) { + if (S_ISREG(gfe->mode)) { if (copy_file(ifd, gfd, 0) < 0) goto err; } + ghost_file_entry__free_unpacked(gfe, NULL); close(ifd); close(gfd); @@ -126,6 +127,8 @@ gf_found: return 0; err: + if (gfe) + ghost_file_entry__free_unpacked(gfe, NULL); xfree(gf->path); xfree(gf); return -1; @@ -178,7 +181,7 @@ static int collect_remaps(void) static int dump_ghost_file(int _fd, u32 id, const struct stat *st) { int img, fd; - struct ghost_file_entry gfe; + GhostFileEntry gfe = GHOST_FILE_ENTRY__INIT; char lpath[32]; pr_info("Dumping ghost file contents (id %#x)\n", id); @@ -191,7 +194,7 @@ static int dump_ghost_file(int _fd, u32 id, const struct stat *st) gfe.gid = st->st_gid; gfe.mode = st->st_mode; - if (write_img(img, &gfe)) + if (pb_write(img, &gfe, ghost_file_entry)) return -1; if (S_ISREG(st->st_mode)) { diff --git a/include/files-reg.h b/include/files-reg.h index 2e1f6e95c..47d815220 100644 --- a/include/files-reg.h +++ b/include/files-reg.h @@ -6,6 +6,7 @@ #include "image.h" #include "../protobuf/regfile.pb-c.h" +#include "../protobuf/ghost-file.pb-c.h" struct cr_fdset; struct fd_parms; diff --git a/include/image.h b/include/image.h index 23177dec9..c84858719 100644 --- a/include/image.h +++ b/include/image.h @@ -80,12 +80,6 @@ struct remap_file_path_entry { */ #define REMAP_GHOST (1 << 31) -struct ghost_file_entry { - u32 uid; - u32 gid; - u32 mode; -} __packed; - struct eventfd_file_entry { u32 id; u16 flags; diff --git a/protobuf/Makefile b/protobuf/Makefile index c05755d48..fa12abb42 100644 --- a/protobuf/Makefile +++ b/protobuf/Makefile @@ -22,6 +22,7 @@ LIBRARY := protobuf-lib.o PROTO_FILES += fdinfo.proto PROTO_FILES += fown.proto PROTO_FILES += regfile.proto +PROTO_FILES += ghost-file.proto HDRS := $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES)) SRCS := $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES)) diff --git a/protobuf/ghost-file.proto b/protobuf/ghost-file.proto new file mode 100644 index 000000000..8f362fad7 --- /dev/null +++ b/protobuf/ghost-file.proto @@ -0,0 +1,5 @@ +message ghost_file_entry { + required uint32 uid = 1; + required uint32 gid = 2; + required uint32 mode = 3; +}