mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-20 16:51:37 +00:00
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 <avagin@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
b65ba9a8d6
commit
3e5ad587f4
3 changed files with 42 additions and 39 deletions
41
cr-dump.c
41
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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__ */
|
||||
|
|
|
|||
37
proc_parse.c
37
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue