[CRIU] [PATCH 16/39] zdtm: reexec the mountpoints test in a target mntns

Andrey Vagin avagin at openvz.org
Mon Apr 21 07:23:26 PDT 2014


Otherwise it will have external files (from another namespace,
which isn't dumped).

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm.sh                        |  1 +
 test/zdtm/lib/test.c                | 18 +++++++++++-------
 test/zdtm/live/static/mountpoints.c | 12 ++++++++++--
 3 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/test/zdtm.sh b/test/zdtm.sh
index 63a6983..fe771f4 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -161,6 +161,7 @@ tempfs
 maps007
 tempfs
 bind-mount
+mountpoints
 "
 
 source $(readlink -f `dirname $0`/env.sh) || exit 1
diff --git a/test/zdtm/lib/test.c b/test/zdtm/lib/test.c
index b492545..585cee2 100644
--- a/test/zdtm/lib/test.c
+++ b/test/zdtm/lib/test.c
@@ -149,6 +149,9 @@ void test_init(int argc, char **argv)
 	setup_outfile();
 	redir_stdfds();
 
+	if (getenv("ZDTM_REEXEC"))
+		goto skip_pid;
+
 	pidf = fopen(pidfile, "wx");
 	if (!pidf) {
 		err("Can't create pid file %s: %m\n", pidfile);
@@ -183,22 +186,23 @@ void test_init(int argc, char **argv)
 		_exit(0);
 	}
 
+	fclose(pidf);
+
+	if (setsid() < 0) {
+		err("Can't become session group leader: %m\n");
+		exit(1);
+	}
+
+skip_pid:
 	/* record the test pid to remember the ownership of the pidfile */
 	master_pid = getpid();
 
-	fclose(pidf);
-
 	sa.sa_handler = SIG_DFL;
 	if (sigaction(SIGCHLD, &sa, NULL)) {
 		err("Can't reset SIGCHLD handler: %m\n");
 		exit(1);
 	}
 
-	if (setsid() < 0) {
-		err("Can't become session group leader: %m\n");
-		exit(1);
-	}
-
 	srand48(time(NULL));	/* just in case we need it */
 }
 
diff --git a/test/zdtm/live/static/mountpoints.c b/test/zdtm/live/static/mountpoints.c
index a733ebd..0b8b26b 100644
--- a/test/zdtm/live/static/mountpoints.c
+++ b/test/zdtm/live/static/mountpoints.c
@@ -8,6 +8,7 @@
 #include <sys/stat.h>
 #include <sched.h>
 #include <sys/wait.h>
+#include <stdlib.h>
 
 #include "zdtmtst.h"
 
@@ -69,6 +70,13 @@ static int test_fn(int argc, char **argv)
 	mode_t old_mask;
 	pid_t pid;
 
+	if (!getenv("ZDTM_REEXEC")) {
+		setenv("ZDTM_REEXEC", "1", 0);
+		return execv(argv[0], argv);
+	} else
+		test_init(argc, argv);
+
+	close(0); /* /dev/null */
 again:
 	fs_cnt = 0;
 	f = fopen("/proc/self/mountinfo", "r");
@@ -254,8 +262,6 @@ done:
 	mknod("/dev/null", 0777 | S_IFCHR, makedev(1, 3));
 	umask(old_mask);
 
-	setup_outfile();
-
 	fd = open(MPTS_ROOT"/kernel/meminfo", O_RDONLY);
 	if (fd == -1)
 		return 1;
@@ -336,6 +342,8 @@ done:
 
 int main(int argc, char **argv)
 {
+	if (getenv("ZDTM_REEXEC"))
+		return test_fn(argc, argv);
 	test_init_ns(argc, argv, CLONE_NEWNS, test_fn);
 	return 0;
 }
-- 
1.8.5.3



More information about the CRIU mailing list