From 9ea2baa2db90f66232c2b9e8ada374356e9ea44d Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Mon, 21 Apr 2014 18:23:26 +0400 Subject: [PATCH] zdtm: reexec the mountpoints test in a target mntns Otherwise it will have external files (from another namespace, which isn't dumped). Signed-off-by: Andrey Vagin Signed-off-by: Pavel Emelyanov --- 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 63a69837d..fe771f45a 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 b4925450e..585cee21f 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 a733ebd4d..0b8b26bcf 100644 --- a/test/zdtm/live/static/mountpoints.c +++ b/test/zdtm/live/static/mountpoints.c @@ -8,6 +8,7 @@ #include #include #include +#include #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; }