[CRIU] [PATCH 2/2] zdtm: show a process tree before and after c/r

Andrey Vagin avagin at openvz.org
Wed Mar 27 10:56:30 EDT 2013


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm.sh                      |  6 +++++-
 test/zdtm/lib/ns.c                | 13 +++++++++++++
 test/zdtm/live/static/session02.c | 12 ++++++------
 3 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/test/zdtm.sh b/test/zdtm.sh
index cf42d05..31b2cbd 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -186,11 +186,15 @@ construct_root()
 {
 	local root=$1
 	local test_path=$2
+	local ps_path=`type -P ps`
 	local libdir=$root/lib
 	local libdir2=$root/lib64
 
+	mkdir $root/bin
+	cp $ps_path $root/bin
+
 	mkdir $libdir $libdir2
-	for i in `ldd $test_path | awk '{ print $1 }' | grep -v vdso`; do
+	for i in `ldd $test_path $ps_path | awk '/^\s/{ print $1 }' | grep -v vdso`; do
 		local lib=`basename $i`
 		[ -f $libdir/$lib ] && continue ||
 		[ -f $i ] && cp $i $libdir && cp $i $libdir2 && continue ||
diff --git a/test/zdtm/lib/ns.c b/test/zdtm/lib/ns.c
index 5eb8186..ead4522 100644
--- a/test/zdtm/lib/ns.c
+++ b/test/zdtm/lib/ns.c
@@ -210,6 +210,13 @@ int ns_init(int argc, char **argv)
 	ret = 1;
 	waitpid(pid, &ret, 0);
 
+
+	pid = fork();
+	if (pid == 0) {
+		execl("/bin/ps", "ps", "axf", "-o", "pid,sid,comm", NULL);
+	} else if (pid > 0)
+		waitpid(pid, NULL, 0);
+
 	/* Daemonize */
 	write(status_pipe, &ret, sizeof(ret));
 	close(status_pipe);
@@ -219,6 +226,12 @@ int ns_init(int argc, char **argv)
 	/* suspend/resume */
 	test_waitsig();
 
+	pid = fork();
+	if (pid == 0) {
+		execl("/bin/ps", "ps", "axf", "-o", "pid,sid,comm", NULL);
+	} else if (pid > 0)
+		waitpid(pid, NULL, 0);
+
 	fd = open(pidfile, O_RDONLY);
 	if (fd == -1) {
 		fprintf(stderr, "open(%s) failed: %m\n", pidfile);
diff --git a/test/zdtm/live/static/session02.c b/test/zdtm/live/static/session02.c
index 6d613e2..201e469 100644
--- a/test/zdtm/live/static/session02.c
+++ b/test/zdtm/live/static/session02.c
@@ -78,7 +78,7 @@ static int clone_func(void *_arg)
 
 	current = args->id;
 
-	test_msg("%d: Hello. My pid is %d\n", args->id, getpid());
+	test_msg("%3d: Hello. My pid is %d\n", args->id, getpid());
 	mainloop();
 	exit(0);
 }
@@ -123,13 +123,13 @@ static void handle_command()
 				goto err;
 			}
 
-			test_msg("%d: fork(%d, %x) = %d\n",
+			test_msg("%3d: fork(%d, %x) = %d\n",
 					current, cmd.arg1, cmd.arg2, pid);
 			processes[cmd.arg1].pid = pid;
 		}
 		break;
 	case TEST_WAIT:
-		test_msg("%d: wait(%d) = %d\n", current,
+		test_msg("%3d: wait(%d) = %d\n", current,
 				cmd.arg1, processes[cmd.arg1].pid);
 
 		if (waitpid(processes[cmd.arg1].pid, NULL, 0) == -1) {
@@ -138,21 +138,21 @@ static void handle_command()
 		}
 		break;
 	case TEST_SUBREAPER:
-		test_msg("%d: subreaper(%d)\n", current, cmd.arg1);
+		test_msg("%3d: subreaper(%d)\n", current, cmd.arg1);
 		if (prctl(PR_SET_CHILD_SUBREAPER, cmd.arg1, 0, 0, 0) == -1) {
 			err("PR_SET_CHILD_SUBREAPER");
 			status = -1;
 		}
 		break;
 	case TEST_SETSID:
-		test_msg("%d: setsid()\n", current);
+		test_msg("%3d: setsid()\n", current);
 		if(setsid() == -1) {
 			err("setsid");
 			status = -1;
 		}
 		break;
 	case TEST_DIE:
-		test_msg("%d: die()\n", current);
+		test_msg("%3d: die()\n", current);
 		processes[current].dead = 1;
 		shutdown(sk, SHUT_RDWR);
 		exit(0);
-- 
1.7.11.7



More information about the CRIU mailing list