From cf0550ce61e322a28c97fe5c1f066876b51bfe0f Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Sun, 22 Jan 2012 20:15:11 +0400 Subject: [PATCH] dump: Images opening rework Rename prep_cr_fdset_for_dump into cr_fdset_open and make it reentable, i.e. every next enter will open more files in the same fdset. Required for zombies and makes the code cleaner. Signed-off-by: Pavel Emelyanov Signed-off-by: Cyrill Gorcunov --- cr-dump.c | 17 +++++++++++------ crtools.c | 13 ++++++++----- include/crtools.h | 2 +- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/cr-dump.c b/cr-dump.c index db29eae06..35efb9b27 100644 --- a/cr-dump.c +++ b/cr-dump.c @@ -1035,7 +1035,7 @@ static int dump_task_threads(struct pstree_item *item) if (item->pid == item->threads[i]) continue; - cr_fdset_thread = prep_cr_fdset_for_dump(item->threads[i], CR_FD_DESC_CORE); + cr_fdset_thread = cr_fdset_open(item->threads[i], CR_FD_DESC_CORE, NULL); if (!cr_fdset_thread) goto err; @@ -1075,6 +1075,10 @@ static int dump_one_task(struct pstree_item *item, struct cr_fdset *cr_fdset) if (ret < 0) goto err; + cr_fdset = cr_fdset_open(item->pid, CR_FD_DESC_NOPSTREE, cr_fdset); + if (!cr_fdset) + goto err; + ret = collect_mappings(pid, pid_dir, &vma_area_list); if (ret) { pr_err("Collect mappings (pid: %d) failed with %d\n", pid, ret); @@ -1178,16 +1182,17 @@ int cr_dump_tasks(pid_t pid, struct cr_options *opts) collect_sockets(); list_for_each_entry(item, &pstree_list, list) { + cr_fdset = cr_fdset_open(item->pid, CR_FD_DESC_NONE, NULL); + if (!cr_fdset) + goto err; + if (item->pid == pid) { - cr_fdset = prep_cr_fdset_for_dump(item->pid, CR_FD_DESC_ALL); + cr_fdset = cr_fdset_open(item->pid, + CR_FD_DESC_USE(CR_FD_PSTREE), cr_fdset); if (!cr_fdset) goto err; if (dump_pstree(pid, &pstree_list, cr_fdset)) goto err; - } else { - cr_fdset = prep_cr_fdset_for_dump(item->pid, CR_FD_DESC_NOPSTREE); - if (!cr_fdset) - goto err; } if (dump_one_task(item, cr_fdset)) diff --git a/crtools.c b/crtools.c index 0a80ccccd..18bd99c12 100644 --- a/crtools.c +++ b/crtools.c @@ -106,20 +106,23 @@ static struct cr_fdset *alloc_cr_fdset(void) return cr_fdset; } -struct cr_fdset *prep_cr_fdset_for_dump(int pid, unsigned long use_mask) +struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask, struct cr_fdset *cr_fdset) { unsigned int i; int ret = -1; char path[PATH_MAX]; - struct cr_fdset *cr_fdset; - cr_fdset = alloc_cr_fdset(); - if (!cr_fdset) - goto err; + if (cr_fdset == NULL) { + cr_fdset = alloc_cr_fdset(); + if (!cr_fdset) + goto err; + } for (i = 0; i < CR_FD_MAX; i++) { if (!(use_mask & CR_FD_DESC_USE(i))) continue; + if (cr_fdset->fds[i] != -1) + continue; ret = get_image_path(path, sizeof(path), fdset_template[i].fmt, pid); diff --git a/include/crtools.h b/include/crtools.h index 698e0af57..d38c5e05c 100644 --- a/include/crtools.h +++ b/include/crtools.h @@ -88,7 +88,7 @@ int cr_restore_tasks(pid_t pid, struct cr_options *opts); int cr_show(unsigned long pid, struct cr_options *opts); int convert_to_elf(char *elf_path, int fd_core); -struct cr_fdset *prep_cr_fdset_for_dump(int pid, unsigned long use_mask); +struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask, struct cr_fdset *); struct cr_fdset *prep_cr_fdset_for_restore(int pid, unsigned long use_mask); void close_cr_fdset(struct cr_fdset **cr_fdset);