[CRIU] [PATCH] test/ptrace_sig: wait children before calling test_daemon

Andrei Vagin avagin at openvz.org
Sat Aug 12 08:58:19 MSK 2017


From: Andrei Vagin <avagin at virtuozzo.com>

A static test has to do nothing after test_daemon().

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 test/zdtm/static/ptrace_sig.c | 31 ++++++++++---------------------
 1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/test/zdtm/static/ptrace_sig.c b/test/zdtm/static/ptrace_sig.c
index 299605de8..f71517717 100644
--- a/test/zdtm/static/ptrace_sig.c
+++ b/test/zdtm/static/ptrace_sig.c
@@ -59,8 +59,8 @@ int main(int argc, char ** argv)
 {
 	int ret, status = 0;
 	pid_t pid, spid, cpid;
-	int signal_pipe[2];
 	int child_pipe[2];
+	siginfo_t siginfo;
 
 	test_init(argc, argv);
 
@@ -81,9 +81,10 @@ int main(int argc, char ** argv)
 	}
 
 	close(child_pipe[1]);
-	ret = pipe(signal_pipe);
-	if (ret < 0) {
-		pr_perror("pipe failed");
+	test_msg("wait while child initialized");
+	ret = read(child_pipe[0], &status, sizeof(status));
+	if  (ret != sizeof(status)) {
+		pr_perror("read from child process failed");
 		return 1;
 	}
 
@@ -92,12 +93,6 @@ int main(int argc, char ** argv)
 		pr_perror("Can't fork signal process");
 		return 1;
 	} else if (spid == 0) {
-		close(signal_pipe[1]);
-		ret = read(signal_pipe[0], &status, sizeof(status));
-		if (ret != sizeof(status)) {
-			pr_perror("read");
-			return 1;
-		}
 		test_msg("send signal to %d\n", cpid);
 		ret = kill(cpid, SIGUSR2);
 		if (ret < 0) {
@@ -105,20 +100,15 @@ int main(int argc, char ** argv)
 		}
 		return 0;
 	}
-	close(signal_pipe[0]);
 
-	test_msg("wait while child initialized");
-	ret = read(child_pipe[0], &status, sizeof(status));
-	if  (ret != sizeof(status)) {
-		pr_perror("read from child process failed");
+	if (waitid(P_PID, spid, &siginfo, WEXITED | WNOWAIT)) {
+		pr_perror("Unable to wait spid");
 		return 1;
 	}
-
-	ret = write(signal_pipe[1], &status, sizeof(status));
-	if (ret != sizeof(status)) {
-		pr_perror("write to signal process failed");
+	if (waitid(P_PID, cpid, &siginfo, WSTOPPED | WNOWAIT)) {
+		pr_perror("Unable to wait cpid");
+		return 1;
 	}
-	close(signal_pipe[1]);
 
 	test_daemon();
 	test_waitsig();
@@ -133,7 +123,6 @@ int main(int argc, char ** argv)
 		}
 
 		if (WIFSTOPPED(status)) {
-			siginfo_t siginfo;
 
 			test_msg("pid=%d stopsig=%d\n", pid, WSTOPSIG(status));
 
-- 
2.13.3



More information about the CRIU mailing list