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

restore: Handle process tree correctly

pstree file is a single one for all processes and
threads so skip non-matched entries correctly.

This brings testee test back to life.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent 1e7bbd35
...@@ -89,8 +89,10 @@ static int nr_shmems; ...@@ -89,8 +89,10 @@ static int nr_shmems;
static struct pipe_info *pipes; static struct pipe_info *pipes;
static int nr_pipes; static int nr_pipes;
static pid_t pstree_pid;
static int restore_task_with_children(int my_pid, char *pstree_path); static int restore_task_with_children(int my_pid, char *pstree_path);
static void sigreturn_restore(pid_t pid); static void sigreturn_restore(pid_t pstree_pid, pid_t pid);
static void show_saved_shmems(void) static void show_saved_shmems(void)
{ {
...@@ -874,7 +876,7 @@ static int prepare_and_execute_image(int pid) ...@@ -874,7 +876,7 @@ static int prepare_and_execute_image(int pid)
if (prepare_image_maps(fd_new, pid)) if (prepare_image_maps(fd_new, pid))
return 1; return 1;
sigreturn_restore(pid); sigreturn_restore(pstree_pid, pid);
if (convert_to_elf(elf_path, fd_new)) if (convert_to_elf(elf_path, fd_new))
return 1; return 1;
...@@ -1285,7 +1287,7 @@ err_or_found: ...@@ -1285,7 +1287,7 @@ err_or_found:
return hint; return hint;
} }
static void sigreturn_restore(pid_t pid) static void sigreturn_restore(pid_t pstree_pid, pid_t pid)
{ {
long restore_task_code_len, restore_task_vma_len; long restore_task_code_len, restore_task_vma_len;
long restore_thread_code_len, restore_thread_vma_len; long restore_thread_code_len, restore_thread_vma_len;
...@@ -1324,7 +1326,7 @@ static void sigreturn_restore(pid_t pid) ...@@ -1324,7 +1326,7 @@ static void sigreturn_restore(pid_t pid)
BUILD_BUG_ON(sizeof(struct task_restore_core_args) & 1); BUILD_BUG_ON(sizeof(struct task_restore_core_args) & 1);
BUILD_BUG_ON(sizeof(struct thread_restore_args) & 1); BUILD_BUG_ON(sizeof(struct thread_restore_args) & 1);
snprintf(path, sizeof(path), "pstree-%d.img", pid); snprintf(path, sizeof(path), "pstree-%d.img", pstree_pid);
fd_pstree = open(path, O_RDONLY, CR_FD_PERM); fd_pstree = open(path, O_RDONLY, CR_FD_PERM);
if (fd_pstree < 0) { if (fd_pstree < 0) {
pr_perror("Can't open %s\n", path); pr_perror("Can't open %s\n", path);
...@@ -1372,8 +1374,13 @@ static void sigreturn_restore(pid_t pid) ...@@ -1372,8 +1374,13 @@ static void sigreturn_restore(pid_t pid)
goto err; goto err;
} }
if (pstree_entry.pid != pid) if (pstree_entry.pid != pid) {
lseek(fd_pstree,
(pstree_entry.nr_children +
pstree_entry.nr_threads) *
sizeof(u32), SEEK_CUR);
continue; continue;
}
if (!pstree_entry.nr_threads) if (!pstree_entry.nr_threads)
break; break;
...@@ -1543,9 +1550,11 @@ err: ...@@ -1543,9 +1550,11 @@ err:
int cr_restore_tasks(pid_t pid, struct cr_options *opts) int cr_restore_tasks(pid_t pid, struct cr_options *opts)
{ {
#if 0 #if 0
sigreturn_restore(pid); sigreturn_restore(pid, pid);
#endif #endif
pstree_pid = pid;
if (opts->leader_only) if (opts->leader_only)
return restore_one_task(pid); return restore_one_task(pid);
return restore_all_tasks(pid); return restore_all_tasks(pid);
......
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