Commit 3c929e54 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

dump: Adopt dumping children for new format

Kernel has a new format for process children
(ie /proc/<pid>/task/<tid>/children) so adopt
crtools for it.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent 894a626a
...@@ -739,50 +739,48 @@ static int parse_threads(pid_t pid, struct pstree_item *item) ...@@ -739,50 +739,48 @@ static int parse_threads(pid_t pid, struct pstree_item *item)
return 0; return 0;
} }
static int parse_children(pid_t pid, u32 *nr_children, u32 **children) static int parse_children(pid_t pid, struct pstree_item *item)
{ {
FILE *file; FILE *file;
char *tok; char *tok;
u32 *ch = NULL; u32 *ch = NULL;
int nr = 1; int nr = 1, i;
file = fopen_proc("%d/children", "r", pid); for (i = 0; i < item->nr_threads; i++) {
if (!file) {
pr_perror("Can't open %d children\n", pid);
goto err;
}
/* file = fopen_fmt("/proc/%d/task/%d/children", "r",
* FIXME: The format of "children" output is not pid, item->threads[i]);
* yet stable enough so be ready to get nothing. if (!file) {
* Moreover, at moment number of children limited pr_perror("Can't open %d children %d\n",
* by the size of a buffer. We need while() here. pid, item->threads[i]);
*/ goto err;
if (!(fgets(loc_buf, sizeof(loc_buf), file))) }
loc_buf[0] = 0;
fclose(file); if (!(fgets(loc_buf, sizeof(loc_buf), file)))
loc_buf[0] = 0;
tok = strtok(loc_buf, " \n"); fclose(file);
while (tok) {
u32 *tmp = xrealloc(ch, nr * sizeof(u32)); tok = strtok(loc_buf, " \n");
if (!tmp) { while (tok) {
xfree(ch); u32 *tmp = xrealloc(ch, nr * sizeof(u32));
goto err; if (!tmp)
goto err;
ch = tmp;
ch[nr - 1] = atoi(tok);
nr++;
tok = strtok(NULL, " \n");
} }
ch = tmp;
ch[nr - 1] = atoi(tok);
nr++;
tok = strtok(NULL, " \n");
} }
*children = ch; item->children = ch;
*nr_children = nr - 1; item->nr_children = nr - 1;
return 0; return 0;
err_close:
fclose(file);
err: err:
xfree(ch);
return -1; return -1;
} }
...@@ -797,10 +795,10 @@ static struct pstree_item *find_pstree_entry(pid_t pid) ...@@ -797,10 +795,10 @@ static struct pstree_item *find_pstree_entry(pid_t pid)
if (parse_threads(pid, item)) if (parse_threads(pid, item))
goto err_free; goto err_free;
if (parse_children(pid, &item->nr_children, &item->children)) if (parse_children(pid, item))
goto err_free; goto err_free;
item->pid = pid; item->pid = pid;
return item; return item;
err_free: err_free:
......
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