diff --git a/cr-show.c b/cr-show.c index 1ec068ca1..3b5b5cb02 100644 --- a/cr-show.c +++ b/cr-show.c @@ -33,6 +33,7 @@ #include "protobuf/fown.pb-c.h" #include "protobuf/fs.pb-c.h" #include "protobuf/pstree.pb-c.h" +#include "protobuf/pipe.pb-c.h" #define DEF_PAGES_PER_LINE 6 @@ -203,19 +204,20 @@ void show_pipes_data(int fd_pipes, struct cr_options *o) void show_pipes(int fd_pipes, struct cr_options *o) { - struct pipe_entry e; + PipeEntry *e; int ret; pr_img_head(CR_FD_PIPES); while (1) { - ret = read_img_eof(fd_pipes, &e); + ret = pb_read_eof(fd_pipes, &e, pipe_entry); if (ret <= 0) goto out; pr_msg("id: 0x%8x pipeid: 0x%8x flags: 0x%8x ", - e.id, e.pipe_id, e.flags); - show_fown_cont(&e.fown); + e->id, e->pipe_id, e->flags); + pb_show_fown_cont(e->fown); pr_msg("\n"); + pipe_entry__free_unpacked(e, NULL); } out: diff --git a/include/image.h b/include/image.h index b74ff9a59..9ed29abe1 100644 --- a/include/image.h +++ b/include/image.h @@ -75,13 +75,6 @@ typedef struct { */ #define REMAP_GHOST (1 << 31) -struct pipe_entry { - u32 id; - u32 pipe_id; - u32 flags; - fown_t fown; -} __packed; - struct pipe_data_entry { u32 pipe_id; u32 bytes; diff --git a/pipes.c b/pipes.c index 48ced6c31..a78c5c6e8 100644 --- a/pipes.c +++ b/pipes.c @@ -11,6 +11,9 @@ #include "pipes.h" #include "util-net.h" +#include "protobuf.h" +#include "protobuf/pipe.pb-c.h" + /* * The sequence of objects which should be restored: * pipe -> files struct-s -> fd-s. @@ -19,7 +22,7 @@ */ struct pipe_info { - struct pipe_entry *pe; + PipeEntry *pe; struct list_head pipe_list; /* All pipe_info with the same pipe_id * This is pure circular list without head */ struct list_head list; /* list head for fdinfo_list_entry-s */ @@ -231,7 +234,7 @@ static int recv_pipe_fd(struct pipe_info *pi) close(tmp); if (fd >= 0) { - if (restore_fown(fd, &pi->pe->fown)) { + if (pb_restore_fown(fd, pi->pe->fown)) { close(fd); return -1; } @@ -288,7 +291,7 @@ static int open_pipe(struct file_desc *d) close(pfd[!(pi->pe->flags & O_WRONLY)]); tmp = pfd[pi->pe->flags & O_WRONLY]; - if (rst_file_params(tmp, &pi->pe->fown, pi->pe->flags)) + if (pb_rst_file_params(tmp, pi->pe->fown, pi->pe->flags)) return -1; return tmp; @@ -322,12 +325,9 @@ int collect_pipes(void) pi = xmalloc(sizeof(*pi)); if (pi == NULL) break; - pi->pe = xmalloc(sizeof(*pi->pe)); - if (pi->pe == NULL) - break; pi->create = 0; - ret = read_img_eof(fd, pi->pe); + ret = pb_read_eof(fd, &pi->pe, pipe_entry); if (ret <= 0) break; @@ -348,7 +348,6 @@ int collect_pipes(void) list_add_tail(&pi->list, &pipes); } - xfree(pi ? pi->pe : NULL); xfree(pi); close(fd); @@ -433,17 +432,20 @@ static struct pipe_data_dump pd_pipes = { .img_type = CR_FD_PIPES_DATA, }; static int dump_one_pipe(int lfd, u32 id, const struct fd_parms *p) { - struct pipe_entry pe; + PipeEntry pe = PIPE_ENTRY__INIT; + FownEntry fown = FOWN_ENTRY__INIT; pr_info("Dumping pipe %d with id %#x pipe_id %#x\n", lfd, id, pipe_id(p)); + pb_prep_fown(&fown, &p->fown); + pe.id = id; pe.pipe_id = pipe_id(p); pe.flags = p->flags; - pe.fown = p->fown; + pe.fown = &fown; - if (write_img(fdset_fd(glob_fdset, CR_FD_PIPES), &pe)) + if (pb_write(fdset_fd(glob_fdset, CR_FD_PIPES), &pe, pipe_entry)) return -1; return dump_one_pipe_data(&pd_pipes, lfd, p); diff --git a/protobuf/Makefile b/protobuf/Makefile index 96662ffd7..c4d647047 100644 --- a/protobuf/Makefile +++ b/protobuf/Makefile @@ -31,6 +31,7 @@ PROTO_FILES += fh.proto PROTO_FILES += inotify.proto PROTO_FILES += fs.proto PROTO_FILES += pstree.proto +PROTO_FILES += pipe.proto HDRS := $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES)) SRCS := $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES)) diff --git a/protobuf/pipe.proto b/protobuf/pipe.proto new file mode 100644 index 000000000..675edbcba --- /dev/null +++ b/protobuf/pipe.proto @@ -0,0 +1,8 @@ +import "fown.proto"; + +message pipe_entry { + required uint32 id = 1; + required uint32 pipe_id = 2; + required uint32 flags = 3; + required fown_entry fown = 4; +}