diff --git a/cr-dump.c b/cr-dump.c index f3d39bcbc..fdcf44437 100644 --- a/cr-dump.c +++ b/cr-dump.c @@ -154,7 +154,7 @@ static int dump_one_fdinfo(const struct fd_parms *p, int lfd, pr_info("fdinfo: type: %2x flags: %4x pos: %8lx addr: %16lx\n", p->type, p->flags, p->pos, p->fd_name); - if (write_img(cr_fdset->fds[CR_FD_FDINFO], &e)) + if (write_img(fdset_fd(cr_fdset, CR_FD_FDINFO), &e)) goto err; ret = 0; @@ -205,7 +205,7 @@ static int dump_pipe_and_data(int lfd, struct pipe_entry *e, int has_bytes; int ret = -1; - fd_pipes = cr_fdset->fds[CR_FD_PIPES]; + fd_pipes = fdset_fd(cr_fdset, CR_FD_PIPES); pr_info("Dumping data from pipe %x\n", e->pipeid); if (pipe(steal_pipe) < 0) { @@ -276,7 +276,7 @@ static int dump_one_pipe(const struct fd_parms *p, unsigned int id, int lfd, if (p->flags & O_WRONLY) { e.bytes = 0; - ret = write_img(cr_fdset->fds[CR_FD_PIPES], &e); + ret = write_img(fdset_fd(cr_fdset, CR_FD_PIPES), &e); } else ret = dump_pipe_and_data(lfd, &e, cr_fdset); @@ -499,12 +499,14 @@ static int dump_task_mappings(pid_t pid, const struct list_head *vma_area_list, const struct cr_fdset *cr_fdset) { struct vma_area *vma_area; - int ret = -1, fd = cr_fdset->fds[CR_FD_VMAS]; + int ret = -1, fd; pr_info("\n"); pr_info("Dumping mappings (pid: %d)\n", pid); pr_info("----------------------------------------\n"); + fd = fdset_fd(cr_fdset, CR_FD_VMAS); + list_for_each_entry(vma_area, vma_area_list, list) { struct vma_entry *vma = &vma_area->vma; @@ -572,7 +574,7 @@ static int dump_task_creds(pid_t pid, const struct parasite_dump_misc *misc, ce.secbits = misc->secbits; - ret = write_img(fds->fds[CR_FD_CREDS], &ce); + ret = write_img(fdset_fd(fds, CR_FD_CREDS), &ce); if (ret < 0) return ret; @@ -787,7 +789,7 @@ static int dump_task_core_all(pid_t pid, const struct proc_pid_stat *stat, core->tc.task_state = TASK_ALIVE; core->tc.exit_code = 0; - ret = dump_task_core(core, cr_fdset->fds[CR_FD_CORE]); + ret = dump_task_core(core, fdset_fd(cr_fdset, CR_FD_CORE)); err_free: free(core); diff --git a/cr-show.c b/cr-show.c index b5f065313..9fa5bede7 100644 --- a/cr-show.c +++ b/cr-show.c @@ -593,7 +593,7 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts) if (!cr_fdset) goto out; - show_core(cr_fdset->fds[CR_FD_CORE], opts->show_pages_content); + show_core(fdset_fd(cr_fdset, CR_FD_CORE), opts->show_pages_content); if (item->nr_threads > 1) { int i, fd_th; @@ -618,21 +618,21 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts) } } - show_vmas(cr_fdset->fds[CR_FD_VMAS]); + show_vmas(fdset_fd(cr_fdset, CR_FD_VMAS)); - show_pipes(cr_fdset->fds[CR_FD_PIPES]); + show_pipes(fdset_fd(cr_fdset, CR_FD_PIPES)); - show_files(cr_fdset->fds[CR_FD_FDINFO]); + show_files(fdset_fd(cr_fdset, CR_FD_FDINFO)); - show_sigacts(cr_fdset->fds[CR_FD_SIGACT]); + show_sigacts(fdset_fd(cr_fdset, CR_FD_SIGACT)); - show_unixsk(cr_fdset->fds[CR_FD_UNIXSK]); + show_unixsk(fdset_fd(cr_fdset, CR_FD_UNIXSK)); - show_inetsk(cr_fdset->fds[CR_FD_INETSK]); + show_inetsk(fdset_fd(cr_fdset, CR_FD_INETSK)); - show_itimers(cr_fdset->fds[CR_FD_ITIMERS]); + show_itimers(fdset_fd(cr_fdset, CR_FD_ITIMERS)); - show_creds(cr_fdset->fds[CR_FD_CREDS]); + show_creds(fdset_fd(cr_fdset, CR_FD_CREDS)); close_cr_fdset(&cr_fdset); diff --git a/crtools.c b/crtools.c index d811f1545..e89dd10ef 100644 --- a/crtools.c +++ b/crtools.c @@ -153,7 +153,7 @@ static struct cr_fdset *alloc_cr_fdset(void) cr_fdset = xmalloc(sizeof(*cr_fdset)); if (cr_fdset) for (i = 0; i < CR_FD_PID_MAX; i++) - cr_fdset->fds[i] = -1; + cr_fdset->_fds[i] = -1; return cr_fdset; } @@ -165,10 +165,10 @@ static void __close_cr_fdset(struct cr_fdset *cr_fdset) return; for (i = 0; i < CR_FD_PID_MAX; i++) { - if (cr_fdset->fds[i] == -1) + if (cr_fdset->_fds[i] == -1) continue; - close_safe(&cr_fdset->fds[i]); - cr_fdset->fds[i] = -1; + close_safe(&cr_fdset->_fds[i]); + cr_fdset->_fds[i] = -1; } } @@ -198,7 +198,7 @@ static struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask, if (!(use_mask & CR_FD_DESC_USE(i))) continue; - if (fdset->fds[i] != -1) + if (fdset->_fds[i] != -1) continue; ret = open_image(i, flags, pid); @@ -209,7 +209,7 @@ static struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask, goto err; } - fdset->fds[i] = ret; + fdset->_fds[i] = ret; } return fdset; diff --git a/include/crtools.h b/include/crtools.h index c44db8a6e..fd8e08389 100644 --- a/include/crtools.h +++ b/include/crtools.h @@ -112,9 +112,14 @@ extern int open_image_ro_nocheck(const char *fmt, ...); #define LAST_PID_PERM 0666 struct cr_fdset { - int fds[CR_FD_PID_MAX]; + int _fds[CR_FD_PID_MAX]; }; +static inline int fdset_fd(const struct cr_fdset *fdset, int type) +{ + return fdset->_fds[type]; +} + #define CR_FD_DESC_USE(type) ((1 << (type))) #define CR_FD_DESC_CORE CR_FD_DESC_USE(CR_FD_CORE) #define CR_FD_DESC_PSTREE CR_FD_DESC_USE(CR_FD_PSTREE) diff --git a/ipc_ns.c b/ipc_ns.c index 2afb50979..704dd9c33 100644 --- a/ipc_ns.c +++ b/ipc_ns.c @@ -428,16 +428,16 @@ static int dump_ipc_data(const struct cr_fdset *fdset) { int ret; - ret = dump_ipc_var(fdset->fds[CR_FD_IPCNS_VAR]); + ret = dump_ipc_var(fdset_fd(fdset, CR_FD_IPCNS_VAR)); if (ret < 0) return ret; - ret = dump_ipc_shm(fdset->fds[CR_FD_IPCNS_SHM]); + ret = dump_ipc_shm(fdset_fd(fdset, CR_FD_IPCNS_SHM)); if (ret < 0) return ret; - ret = dump_ipc_msg(fdset->fds[CR_FD_IPCNS_MSG]); + ret = dump_ipc_msg(fdset_fd(fdset, CR_FD_IPCNS_MSG)); if (ret < 0) return ret; - ret = dump_ipc_sem(fdset->fds[CR_FD_IPCNS_SEM]); + ret = dump_ipc_sem(fdset_fd(fdset, CR_FD_IPCNS_SEM)); if (ret < 0) return ret; return 0; diff --git a/namespaces.c b/namespaces.c index c7908d96f..d0dc25666 100644 --- a/namespaces.c +++ b/namespaces.c @@ -122,20 +122,20 @@ int try_show_namespaces(int ns_pid) if (!fdset) return -1; - if (fdset->fds[CR_FD_UTSNS] != -1) - show_utsns(fdset->fds[CR_FD_UTSNS]); + if (fdset_fd(fdset, CR_FD_UTSNS) != -1) + show_utsns(fdset_fd(fdset, CR_FD_UTSNS)); - if (fdset->fds[CR_FD_IPCNS_VAR] != -1) - show_ipc_var(fdset->fds[CR_FD_IPCNS_VAR]); + if (fdset_fd(fdset, CR_FD_IPCNS_VAR) != -1) + show_ipc_var(fdset_fd(fdset, CR_FD_IPCNS_VAR)); - if (fdset->fds[CR_FD_IPCNS_SHM] != -1) - show_ipc_shm(fdset->fds[CR_FD_IPCNS_SHM]); + if (fdset_fd(fdset, CR_FD_IPCNS_SHM) != -1) + show_ipc_shm(fdset_fd(fdset, CR_FD_IPCNS_SHM)); - if (fdset->fds[CR_FD_IPCNS_MSG] != -1) - show_ipc_msg(fdset->fds[CR_FD_IPCNS_MSG]); + if (fdset_fd(fdset, CR_FD_IPCNS_MSG) != -1) + show_ipc_msg(fdset_fd(fdset, CR_FD_IPCNS_MSG)); - if (fdset->fds[CR_FD_IPCNS_SEM] != -1) - show_ipc_sem(fdset->fds[CR_FD_IPCNS_SEM]); + if (fdset_fd(fdset, CR_FD_IPCNS_SEM) != -1) + show_ipc_sem(fdset_fd(fdset, CR_FD_IPCNS_SEM)); close_cr_fdset(&fdset); return 0; diff --git a/parasite-syscall.c b/parasite-syscall.c index f2ffdb849..7faeb2ab2 100644 --- a/parasite-syscall.c +++ b/parasite-syscall.c @@ -390,7 +390,7 @@ static int parasite_file_cmd(char *what, int cmd, int type, pr_info("Dumping %s (pid: %d)\n", what, ctl->pid); pr_info("----------------------------------------\n"); - fd = cr_fdset->fds[type]; + fd = fdset_fd(cr_fdset, type); ret = parasite_prep_file(fd, ctl); if (ret < 0) goto out; @@ -534,7 +534,7 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_a pr_info("Dumping pages (type: %d pid: %d)\n", CR_FD_PAGES, ctl->pid); pr_info("----------------------------------------\n"); - ret = parasite_prep_file(cr_fdset->fds[CR_FD_PAGES], ctl); + ret = parasite_prep_file(fdset_fd(cr_fdset, CR_FD_PAGES), ctl); if (ret < 0) goto out; @@ -591,7 +591,7 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_a parasite_execute(PARASITE_CMD_DUMPPAGES_FINI, ctl, NULL, 0); - if (write_img(cr_fdset->fds[CR_FD_PAGES], &zero_page_entry)) + if (write_img(fdset_fd(cr_fdset, CR_FD_PAGES), &zero_page_entry)) goto out; pr_info("\n"); @@ -599,7 +599,7 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_a ret = 0; out: - fchmod(cr_fdset->fds[CR_FD_PAGES], CR_FD_PERM); + fchmod(fdset_fd(cr_fdset, CR_FD_PAGES), CR_FD_PERM); pr_info("----------------------------------------\n"); return ret; diff --git a/sockets.c b/sockets.c index 150b4267a..476688da1 100644 --- a/sockets.c +++ b/sockets.c @@ -261,7 +261,7 @@ static int dump_one_inet(const struct socket_desc *_sk, int fd, memcpy(ie.src_addr, sk->src_addr, sizeof(u32) * 4); memcpy(ie.dst_addr, sk->dst_addr, sizeof(u32) * 4); - if (write_img(cr_fdset->fds[CR_FD_INETSK], &ie)) + if (write_img(fdset_fd(cr_fdset, CR_FD_INETSK), &ie)) goto err; pr_info("Dumping inet socket at %d\n", fd); @@ -349,9 +349,9 @@ static int dump_one_unix(const struct socket_desc *_sk, int fd, ue.id, ue.peer); } - if (write_img(cr_fdset->fds[CR_FD_UNIXSK], &ue)) + if (write_img(fdset_fd(cr_fdset, CR_FD_UNIXSK), &ue)) goto err; - if (write_img_buf(cr_fdset->fds[CR_FD_UNIXSK], sk->name, ue.namelen)) + if (write_img_buf(fdset_fd(cr_fdset, CR_FD_UNIXSK), sk->name, ue.namelen)) goto err; if (sk->rqlen != 0 && !(sk->type == SOCK_STREAM && diff --git a/uts_ns.c b/uts_ns.c index 65789fd97..8df32143c 100644 --- a/uts_ns.c +++ b/uts_ns.c @@ -36,7 +36,7 @@ int dump_uts_ns(int ns_pid, struct cr_fdset *fdset) return ret; } - fd = fdset->fds[CR_FD_UTSNS]; + fd = fdset_fd(fdset, CR_FD_UTSNS); ret = dump_uts_string(fd, ubuf.nodename); if (!ret)