2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 06:15:24 +00:00

criu: Restore tasks as siblings in swrk

Andrey validly pointed out, that restoring pdeath_sig is not
compatible with criu_restore_child() call -- after criu restore
children, it will exit and fire the pdeath_sig into restored
tree root, potentially killing it.

The fix for that could be -- when started in swrk more, criu can
restore tree not as children tasks, but as siblings, using the
CLONE_PARENT flag when fork()-ing the root task.

With this we should also take care about errors handing -- right
now criu catches the SIGCHILD from dying children tasks, and
since we plan to create them be children of the criu parent (the
library caller) we will not be able to catch them. To do so we
SEIZE the root task in advance thus causing all SIGCHLD-s go to
criu, not to its parent.

Having this done we no longer need the SUBREAPER trick in the
library call -- tasks get restored right as callers kids :)

Some thoughts for future -- using this trick we can finally make
"natural" restoration of shell jobs. I.e. -- make criu restore
some subtree right under bash, w/o leaving itself as intermediate
task and w/o re-parenting the subtree to init after restore.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrey Vagin <avagin@parallels.com>
This commit is contained in:
Pavel Emelyanov
2014-06-30 20:30:44 +04:00
parent fba8aae300
commit 84eb0a1927
4 changed files with 54 additions and 21 deletions

View File

@@ -15,10 +15,6 @@
#include "rpc.pb-c.h"
#include "cr-service-const.h"
#ifndef PR_SET_CHILD_SUBREAPER
#define PR_SET_CHILD_SUBREAPER 36
#endif
const char *criu_lib_version = CRIU_VERSION;
static char *service_address = CR_DEFAULT_SERVICE_ADDRESS;
@@ -582,15 +578,6 @@ int criu_restore_child(void)
if (socketpair(PF_LOCAL, SOCK_SEQPACKET, 0, sks))
goto out;
/*
* Set us as child subreaper so that after the swrk
* finishes restore and exits the restored subtree
* gets reparented to us.
*/
if (prctl(PR_SET_CHILD_SUBREAPER, 1, 0, 0))
goto err;
pid = fork();
if (pid < 0)
goto err;
@@ -633,8 +620,6 @@ int criu_restore_child(void)
close(sks[0]);
waitpid(pid, NULL, 0);
/* Drop the subreaper role _after_ swrk exits */
prctl(PR_SET_CHILD_SUBREAPER, 0, 0, 0);
if (!ret) {
ret = resp->success ? resp->restore->pid : -EBADE;