From 3e5ad587f4e514dc565ae8bdaeb16d8618f987cf Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Mon, 23 Sep 2013 14:33:30 +0400 Subject: [PATCH] parse_proc: move parse_threads from cr-dump.c It will be used in cr-restore.c for stopping threads on the exit from sigreturn. Signed-off-by: Andrey Vagin Signed-off-by: Pavel Emelyanov --- cr-dump.c | 41 ++--------------------------------------- include/proc_parse.h | 3 +++ proc_parse.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 39 deletions(-) diff --git a/cr-dump.c b/cr-dump.c index ba7a7cccb..247cc26dd 100644 --- a/cr-dump.c +++ b/cr-dump.c @@ -675,46 +675,9 @@ err: return ret; } -static int parse_threads(const struct pstree_item *item, struct pid **_t, int *_n) -{ - struct dirent *de; - DIR *dir; - struct pid *t = NULL; - int nr = 1; - - dir = opendir_proc(item->pid.real, "task"); - if (!dir) - return -1; - - while ((de = readdir(dir))) { - struct pid *tmp; - - /* We expect numbers only here */ - if (de->d_name[0] == '.') - continue; - - tmp = xrealloc(t, nr * sizeof(struct pid)); - if (!tmp) { - xfree(t); - return -1; - } - t = tmp; - t[nr - 1].real = atoi(de->d_name); - t[nr - 1].virt = -1; - nr++; - } - - closedir(dir); - - *_t = t; - *_n = nr - 1; - - return 0; -} - static int get_threads(struct pstree_item *item) { - return parse_threads(item, &item->threads, &item->nr_threads); + return parse_threads(item->pid.real, &item->threads, &item->nr_threads); } static int check_threads(const struct pstree_item *item) @@ -722,7 +685,7 @@ static int check_threads(const struct pstree_item *item) struct pid *t; int nr, ret; - ret = parse_threads(item, &t, &nr); + ret = parse_threads(item->pid.real, &t, &nr); if (ret) return ret; diff --git a/include/proc_parse.h b/include/proc_parse.h index a1245cbb4..71bf00b44 100644 --- a/include/proc_parse.h +++ b/include/proc_parse.h @@ -164,4 +164,7 @@ extern int parse_file_locks(void); extern int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat * args); +struct pid; +extern int parse_threads(int pid, struct pid **_t, int *_n); + #endif /* __CR_PROC_PARSE_H__ */ diff --git a/proc_parse.c b/proc_parse.c index 3409a85d3..dd56ed10e 100644 --- a/proc_parse.c +++ b/proc_parse.c @@ -1238,3 +1238,40 @@ out: fclose(file); return ret; } + +int parse_threads(int pid, struct pid **_t, int *_n) +{ + struct dirent *de; + DIR *dir; + struct pid *t = NULL; + int nr = 1; + + dir = opendir_proc(pid, "task"); + if (!dir) + return -1; + + while ((de = readdir(dir))) { + struct pid *tmp; + + /* We expect numbers only here */ + if (de->d_name[0] == '.') + continue; + + tmp = xrealloc(t, nr * sizeof(struct pid)); + if (!tmp) { + xfree(t); + return -1; + } + t = tmp; + t[nr - 1].real = atoi(de->d_name); + t[nr - 1].virt = -1; + nr++; + } + + closedir(dir); + + *_t = t; + *_n = nr - 1; + + return 0; +}