Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/checkpoint-restore/criu.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@google.com>2022-03-20 10:43:45 +0300
committerAndrei Vagin <avagin@gmail.com>2022-04-29 03:53:52 +0300
commit791651f1b69b527d124282ff85d2f65d92759f1e (patch)
tree6e23b2ac4da52f67a5566469439c09a272350912 /scripts
parent805559c1deb6507a0c2ffbe0d4a3d18257322fbd (diff)
criu-ns: add a helper to hold a pid namespace
The init process can exit if it doesn't have any child processes and its pidns is destroyed in this case. CRIU dump is running in the target pid namespace and it kills dumped processes at the end. We need to create a holder process to be sure that the pid namespace will not be destroy before criu exits. Fixes: #1775 Signed-off-by: Andrei Vagin <avagin@gmail.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/criu-ns23
1 files changed, 23 insertions, 0 deletions
diff --git a/scripts/criu-ns b/scripts/criu-ns
index 930d20c80..9fc58b640 100755
--- a/scripts/criu-ns
+++ b/scripts/criu-ns
@@ -82,6 +82,27 @@ def run_criu(args):
raise OSError(errno.ENOENT, "No such command")
+# pidns_holder creates a process that is reparented to the init.
+#
+# The init process can exit if it doesn't have any child processes and its
+# pidns is destroyed in this case. CRIU dump is running in the target pid
+# namespace and it kills dumped processes at the end. We need to create a
+# holder process to be sure that the pid namespace will not be destroy before
+# criu exits.
+def pidns_holder():
+ r, w = os.pipe()
+ pid = os.fork()
+ if pid == 0:
+ pid = os.fork()
+ if pid == 0:
+ os.close(w)
+ # The write end is owned by the parent process and it is closed by
+ # kernel when the parent process exits.
+ os.read(r, 1)
+ sys.exit(0)
+ os.waitpid(pid, 0)
+
+
def wrap_restore():
restore_args = sys.argv[1:]
if '--restore-sibling' in restore_args:
@@ -200,6 +221,8 @@ def wrap_dump():
set_pidns(pid, pid_idx)
set_mntns(pid)
+ pidns_holder()
+
criu_pid = os.fork()
if criu_pid == 0:
run_criu(sys.argv[1:])