mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 06:15:24 +00:00
ctrools: Rewrite task/threads stopping engine
Stopping tasks with STOP and proceeding with SEIZE is actually excessive -- the SEIZE if enough. Moreover, just killing a task with STOP is also racy, since task should be given some time to come to sleep before its proc can be parsed. Rewrite all this code to SEIZE task and all its threads from the very beginning. With this we can distinguish stopped task state and migrate it properly (not supported now, need to implement). This thing however has one BIG problem -- after we SEIZE-d a task we should seize it's threads, but we should do it in a loop -- reading /proc/pid/task and seizing them again and again, until the contents of this dir stops changing (not done now). Besides, after we seized a task and all its threads we cannot scan it's children list once -- task can get reparented to init and any task's child can call clone with CLONE_PARENT flag thus repopulating the children list of the already seized task (not done also) This patch is ugly, yes, but splitting it doesn't help to review it much, sorry :( Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This commit is contained in:
committed by
Cyrill Gorcunov
parent
501d85193c
commit
6da51eee3f
30
proc_parse.c
30
proc_parse.c
@@ -175,6 +175,36 @@ err_bogus_mapping:
|
||||
goto err;
|
||||
}
|
||||
|
||||
int parse_pid_stat_small(pid_t pid, int pid_dir, struct proc_pid_stat_small *s)
|
||||
{
|
||||
FILE *f;
|
||||
char *tok;
|
||||
int n;
|
||||
|
||||
f = fopen_proc(pid_dir, "stat");
|
||||
if (f == NULL) {
|
||||
pr_perror("Can't open %d's stat", pid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(s, 0, sizeof(*s));
|
||||
n = fscanf(f, "%d " PROC_TASK_COMM_LEN_FMT " %c",
|
||||
&s->pid, s->comm, &s->state);
|
||||
|
||||
if (n < 3) {
|
||||
pr_err("Parsing %d's stat failed (#fields do not match)\n", pid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
s->comm[PROC_TASK_COMM_LEN-1] = '\0';
|
||||
tok = strchr(s->comm, ')');
|
||||
if (tok)
|
||||
*tok = '\0';
|
||||
fclose(f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_pid_stat(pid_t pid, int pid_dir, struct proc_pid_stat *s)
|
||||
{
|
||||
FILE *f;
|
||||
|
Reference in New Issue
Block a user