[CRIU] [PATCH v2] test: add processes tree restoring test

Kinsbursky Stanislav skinsbursky at openvz.org
Thu Nov 1 04:01:16 EDT 2012


From: Stanislav Kinsbursky <skinsbursky at openvz.org>

This test makes sure, that processes tree is restored before opened files.
This is guaranteed by holding child's "/proc/<pid>/stat" file opened by parent.

It was inspired by OpenVZ bug:
http://bugzilla.openvz.org/show_bug.cgi?id=2404

IOW, OpenVZ can't restore container with such test inside.

v2:
1) Test renamed + carefull cleanup + minor updates.

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
 test/zdtm.sh                              |    1 
 test/zdtm/live/static/Makefile            |    1 
 test/zdtm/live/static/child_opened_proc.c |   63 +++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 0 deletions(-)
 create mode 100644 test/zdtm/live/static/child_opened_proc.c
-------------- next part --------------
diff --git a/test/zdtm.sh b/test/zdtm.sh
index e7d8128..41cedeb 100644
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -65,6 +65,7 @@ transition/fork
 static/pty00
 static/pty01
 static/pty04
+static/child_opened_proc
 "
 # Duplicate list with ns/ prefix
 TEST_LIST=$TEST_LIST$(echo $TEST_LIST | tr ' ' '\n' | sed 's#^#ns/#')
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 03e40fe..18ce2eb 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -72,6 +72,7 @@ TST_NOFILE	=				\
 		socket-ext			\
 		unhashed_proc			\
 		cow00				\
+		child_opened_proc		\
 		posix_timers			\
 #		jobctl00			\
 
diff --git a/test/zdtm/live/static/child_opened_proc.c b/test/zdtm/live/static/child_opened_proc.c
new file mode 100644
index 0000000..06f37cf
--- /dev/null
+++ b/test/zdtm/live/static/child_opened_proc.c
@@ -0,0 +1,63 @@
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check that tree prior to files opening";
+const char *test_author	= "Stanislav Kinsbursky <skinsbursky at paralles.com";
+
+int main(int argc, char ** argv)
+{
+	int pid, err = 0;
+	int proc_fd;
+	char name[64];
+
+	test_init(argc, argv);
+
+	pid = test_fork();
+	if (pid < 0) {
+		err("Can't fork");
+		exit(1);
+	}
+
+	if (!pid) {
+		test_waitsig();
+		return 0;
+	}
+
+	sprintf(name, "/proc/%d/stat", pid);
+	proc_fd = open(name, O_RDONLY);
+	if (proc_fd == -1) {
+		err("can't open %s: %m\n", name);
+		err++;
+		goto out;
+	}
+	test_daemon();
+	test_waitsig();
+
+	if (close(proc_fd) == -1) {
+		err("Failed to close %s\n", name);
+		err++;
+	}
+out:
+	if (kill(pid, SIGTERM) == -1) {
+		err("Failed to terminate child\n");
+		err++;
+	} else {
+		if (waitpid(pid, NULL, 0) != pid) {
+			err("Failed to collect killed child\n");
+			err++;
+		}
+	}
+
+	if (!err)
+		pass();
+
+	return err;
+}


More information about the CRIU mailing list