Commit 760994c6 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

dump: get children by pid instead of pstree_item

pstree_item contains virtual and real pid and we want to
get children by both of this pids.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent f6d373cc
...@@ -954,16 +954,26 @@ static int check_threads(const struct pstree_item *item) ...@@ -954,16 +954,26 @@ static int check_threads(const struct pstree_item *item)
return 0; return 0;
} }
static int parse_children(const struct pstree_item *item, u32 **_c, int *_n) static int parse_children(int pid, u32 **_c, int *_n)
{ {
FILE *file; FILE *file;
char *tok; char *tok;
u32 *ch = NULL; u32 *ch = NULL;
int nr = 1, i; int nr = 1;
DIR *dir;
struct dirent *de;
for (i = 0; i < item->nr_threads; i++) { dir = opendir_proc(pid, "task");
file = fopen_proc(item->pid.real, "task/%d/children", if (dir == NULL)
item->threads[i].real); return -1;
while ((de = readdir(dir))) {
if (!strcmp(de->d_name, "."))
continue;
if (!strcmp(de->d_name, ".."))
continue;
file = fopen_proc(pid, "task/%s/children", de->d_name);
if (!file) if (!file)
goto err; goto err;
...@@ -988,9 +998,10 @@ static int parse_children(const struct pstree_item *item, u32 **_c, int *_n) ...@@ -988,9 +998,10 @@ static int parse_children(const struct pstree_item *item, u32 **_c, int *_n)
*_c = ch; *_c = ch;
*_n = nr - 1; *_n = nr - 1;
closedir(dir);
return 0; return 0;
err: err:
closedir(dir);
xfree(ch); xfree(ch);
return -1; return -1;
} }
...@@ -1001,7 +1012,7 @@ static int get_children(struct pstree_item *item) ...@@ -1001,7 +1012,7 @@ static int get_children(struct pstree_item *item)
int ret, i, nr_children; int ret, i, nr_children;
struct pstree_item *c; struct pstree_item *c;
ret = parse_children(item, &ch, &nr_children); ret = parse_children(item->pid.real, &ch, &nr_children);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -1143,7 +1154,7 @@ static int check_subtree(const struct pstree_item *item) ...@@ -1143,7 +1154,7 @@ static int check_subtree(const struct pstree_item *item)
int nr, ret, i; int nr, ret, i;
struct pstree_item *child; struct pstree_item *child;
ret = parse_children(item, &ch, &nr); ret = parse_children(item->pid.real, &ch, &nr);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment