diff --git a/cr-restore.c b/cr-restore.c index 64815c90b..b7d050daa 100644 --- a/cr-restore.c +++ b/cr-restore.c @@ -1213,7 +1213,7 @@ static int restore_task_with_children(int my_pid) return restore_one_task(my_pid); } -static int restore_root_task(int fd) +static int restore_root_task(int fd, bool detach) { struct pstree_entry e; int ret, i; @@ -1240,11 +1240,12 @@ static int restore_root_task(int fd) pr_info("Go on!!!\n"); cr_wait_set(&task_entries->start, 1); - wait(NULL); + if (!detach) + wait(NULL); return 0; } -static int restore_all_tasks(pid_t pid) +static int restore_all_tasks(pid_t pid, bool detach) { int pstree_fd; u32 type = 0; @@ -1256,7 +1257,7 @@ static int restore_all_tasks(pid_t pid) if (prepare_shared(pstree_fd)) return -1; - return restore_root_task(pstree_fd); + return restore_root_task(pstree_fd, detach); } static long restorer_get_vma_hint(pid_t pid, struct list_head *self_vma_list, long vma_len) @@ -1623,5 +1624,5 @@ int cr_restore_tasks(pid_t pid, struct cr_options *opts) if (opts->leader_only) return restore_one_task(pid); - return restore_all_tasks(pid); + return restore_all_tasks(pid, opts->restore_detach); } diff --git a/crtools.c b/crtools.c index 1a61589ac..0a80ccccd 100644 --- a/crtools.c +++ b/crtools.c @@ -218,7 +218,7 @@ int main(int argc, char *argv[]) int action = -1; int log_inited = 0; - static const char short_opts[] = "f:p:t:hcD:o:"; + static const char short_opts[] = "df:p:t:hcD:o:"; BUILD_BUG_ON(PAGE_SIZE != PAGE_IMAGE_SIZE); @@ -250,6 +250,9 @@ int main(int argc, char *argv[]) case 'f': opts.show_dump_file = optarg; break; + case 'd': + opts.restore_detach = true; + break; case 'D': if (chdir(optarg)) { pr_perror("can't change working directory"); @@ -322,6 +325,7 @@ usage: printk(" -c in case of checkpoint -- continue running the process after\n" " checkpoint complete, in case of showing file contents --\n" " show contents of pages dumped in hexdump format\n"); + printk(" -d detach after restore\n"); printk("\nAdditional common parameters:\n"); printk(" -D dir save checkpoint files in specified directory\n"); diff --git a/include/crtools.h b/include/crtools.h index ed3af5d94..698e0af57 100644 --- a/include/crtools.h +++ b/include/crtools.h @@ -40,6 +40,7 @@ struct cr_options { enum cr_task_state final_state; bool show_pages_content; char *show_dump_file; + bool restore_detach; }; /* file descriptors template */ diff --git a/test/zdtm.sh b/test/zdtm.sh index e6ed06a8a..ea50841b1 100644 --- a/test/zdtm.sh +++ b/test/zdtm.sh @@ -44,11 +44,9 @@ run_test() echo Waiting... sleep 1 done - setsid $CRTOOLS restore -D $ddump -o restore.log -t $pid & - sleep 1 + setsid $CRTOOLS restore -D $ddump -o restore.log -d -t $pid || return 1 ls -l /proc/$pid/fd/ make -C $tdir $tname.out - wait || return 1 for i in `seq 5`; do test -f $test.out && break; echo Waiting...