[CRIU] [PATCH 4/4] zdtm: Add zombie01 test

Kirill Tkhai ktkhai at virtuozzo.com
Thu Dec 28 12:35:56 MSK 2017


Create a zombie with specific pgid and check that
pgid remains the same after restore.

This test hangs criu restore without any of two previous patches:
1)without "restore: Call prepare_fds() in restore_one_zombie()"
  in 100% cases;

2)without "restore: Split restore_one_helper() and wait exiting
  zombie children" fail is racy, but you can add something like

--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1130,6 +1130,8 @@ static int restore_one_zombie(CoreEntry *core)

        if (task_entries != NULL) {
                restore_finish_stage(task_entries, CR_STATE_RESTORE);
+               if (current->parent->pid->state == TASK_ALIVE)
+                       sleep(2);
                zombie_prepare_signals();
        }

and it will fail with almost 100% probability.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 test/zdtm/static/Makefile      |    1 +
 test/zdtm/static/zombie01.c    |   80 ++++++++++++++++++++++++++++++++++++++++
 test/zdtm/static/zombie01.desc |    1 +
 3 files changed, 82 insertions(+)
 create mode 100644 test/zdtm/static/zombie01.c
 create mode 100644 test/zdtm/static/zombie01.desc

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index 16ea0f042..ff2473125 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -10,6 +10,7 @@ TST_NOFILE	:=				\
 		caps00				\
 		wait00				\
 		zombie00			\
+		zombie01			\
 		fpu00				\
 		fpu01				\
 		arm-neon00			\
diff --git a/test/zdtm/static/zombie01.c b/test/zdtm/static/zombie01.c
new file mode 100644
index 000000000..6e904c047
--- /dev/null
+++ b/test/zdtm/static/zombie01.c
@@ -0,0 +1,80 @@
+#include <sched.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check that zombie pgid is restored";
+const char *test_author	= "Kirill Tkhai <ktkhai at virtuozzo.com>";
+
+int main(int argc, char **argv)
+{
+	pid_t pid, pgrp;
+	siginfo_t info;
+	int status;
+
+	test_init(argc, argv);
+
+	pid = fork();
+	if (pid < 0) {
+		fail("fork");
+		exit(1);
+	}
+
+	if (!pid) {
+		/* Child */
+		if (setpgid(0, 0) < 0) {
+			fail("setpgid");
+			exit(1);
+		}
+		pid = sys_clone_unified(CLONE_PARENT|SIGCHLD, NULL, NULL, NULL, 0);
+		if (pid < 0) {
+			fail("fork");
+			exit(1);
+		}
+
+		exit(0);
+	}
+
+	if (waitpid(pid, &status, 0) < 0) {
+		fail("waitpid");
+		exit(1);
+	}
+	if (!WIFEXITED(status) || WEXITSTATUS(status)) {
+		pr_err("Exited with problems: status=%d\n", status);
+		fail("fail");
+		exit(1);
+	}
+
+	if (waitid(P_ALL, 0, &info, WEXITED|WNOWAIT) < 0) {
+		fail("waitpid");
+		exit(1);
+	}
+
+	test_daemon();
+	test_waitsig();
+
+	if (waitid(P_ALL, 0, &info, WEXITED|WNOWAIT) < 0) {
+		fail("waitpid");
+		exit(1);
+	}
+
+	pgrp = getpgid(info.si_pid);
+	if (pgrp < 0) {
+		fail("getpgrp");
+		exit(1);
+	}
+
+	if (pgrp != pid) {
+		pr_err("Wrong pgrp: %d != %d\n", pgrp, pid);
+		fail("fail");
+		exit(1);
+	}
+
+	pass();
+	return 0;
+}
diff --git a/test/zdtm/static/zombie01.desc b/test/zdtm/static/zombie01.desc
new file mode 100644
index 000000000..2eac7e654
--- /dev/null
+++ b/test/zdtm/static/zombie01.desc
@@ -0,0 +1 @@
+{'flags': 'suid'}



More information about the CRIU mailing list