[CRIU] [PATCH 2/3] zdtm: Factor out ps showing code

Pavel Emelyanov xemul at parallels.com
Thu Dec 3 04:06:01 PST 2015


Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 test/zdtm/lib/ns.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/test/zdtm/lib/ns.c b/test/zdtm/lib/ns.c
index f8a6816..69d2d51 100644
--- a/test/zdtm/lib/ns.c
+++ b/test/zdtm/lib/ns.c
@@ -218,6 +218,19 @@ static int ns_exec(void *_arg)
 	return -1;
 }
 
+static void show_ps(void)
+{
+	int pid;
+
+	pid = fork();
+	if (pid == 0) {
+		execl("/bin/ps", "ps", "axf", "-o", "pid,sid,comm", NULL);
+		fprintf(stderr, "Unable to execute ps: %m\n");
+		exit(1);
+	} else if (pid > 0)
+		waitpid(pid, NULL, 0);
+}
+
 int ns_init(int argc, char **argv)
 {
 	struct sigaction sa = {
@@ -261,13 +274,7 @@ int ns_init(int argc, char **argv)
 	else if (ret)
 		fprintf(stderr, "The test returned non-zero code %d\n", ret);
 
-	pid = fork();
-	if (pid == 0) {
-		execl("/bin/ps", "ps", "axf", "-o", "pid,sid,comm", NULL);
-		fprintf(stderr, "Unable to execute ps: %m\n");
-		exit(1);
-	} else if (pid > 0)
-		waitpid(pid, NULL, 0);
+	show_ps();
 
 	if (sigaction(SIGCHLD, &sa, NULL)) {
 		fprintf(stderr, "Can't set SIGCHLD handler: %m\n");
@@ -297,13 +304,7 @@ 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);
-		fprintf(stderr, "Unable to execute ps: %m\n");
-		exit(1);
-	} else if (pid > 0)
-		waitpid(pid, NULL, 0);
+	show_ps();
 
 	fd = open(pidfile, O_RDONLY);
 	if (fd == -1) {
-- 
1.9.3




More information about the CRIU mailing list