Commit dbd41b52 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

proc: allow parse_thread to use an existent buffer

parse_thread allocated a buffer for threads and then it initialized read
pid for each thread.

Now we want to use it on restore and in this moment we already have
a buffer with initialized virt pid-s, so we need to initialize read
pid-s only.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 3e5ad587
......@@ -682,7 +682,7 @@ static int get_threads(struct pstree_item *item)
static int check_threads(const struct pstree_item *item)
{
struct pid *t;
struct pid *t = NULL;
int nr, ret;
ret = parse_threads(item->pid.real, &t, &nr);
......
......@@ -1246,6 +1246,9 @@ int parse_threads(int pid, struct pid **_t, int *_n)
struct pid *t = NULL;
int nr = 1;
if (*_t)
t = *_t;
dir = opendir_proc(pid, "task");
if (!dir)
return -1;
......@@ -1257,21 +1260,26 @@ int parse_threads(int pid, struct pid **_t, int *_n)
if (de->d_name[0] == '.')
continue;
tmp = xrealloc(t, nr * sizeof(struct pid));
if (!tmp) {
xfree(t);
return -1;
if (*_t == NULL) {
tmp = xrealloc(t, nr * sizeof(struct pid));
if (!tmp) {
xfree(t);
return -1;
}
t = tmp;
t[nr - 1].virt = -1;
}
t = tmp;
t[nr - 1].real = atoi(de->d_name);
t[nr - 1].virt = -1;
nr++;
}
closedir(dir);
*_t = t;
*_n = nr - 1;
if (*_t == NULL) {
*_t = t;
*_n = nr - 1;
} else
BUG_ON(nr - 1 != *_n);
return 0;
}
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