Commit 3e5ad587 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

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: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent b65ba9a8
...@@ -675,46 +675,9 @@ err: ...@@ -675,46 +675,9 @@ err:
return ret; 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) 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) static int check_threads(const struct pstree_item *item)
...@@ -722,7 +685,7 @@ 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; struct pid *t;
int nr, ret; int nr, ret;
ret = parse_threads(item, &t, &nr); ret = parse_threads(item->pid.real, &t, &nr);
if (ret) if (ret)
return ret; return ret;
......
...@@ -164,4 +164,7 @@ extern int parse_file_locks(void); ...@@ -164,4 +164,7 @@ extern int parse_file_locks(void);
extern int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat * args); 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__ */ #endif /* __CR_PROC_PARSE_H__ */
...@@ -1238,3 +1238,40 @@ out: ...@@ -1238,3 +1238,40 @@ out:
fclose(file); fclose(file);
return ret; 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;
}
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