[CRIU] [PATCH v3 2/5] tests: add a ZDTM_NOREAP variable

Tycho Andersen tycho.andersen at canonical.com
Wed Jul 13 08:10:54 PDT 2016


We'll use this variable in the next test to make sure the test suite
doesn't accidentally reap the zombie we want to leave around for the actual
test.

This is kind of ugly and there might be a better way to pass information to
the test's init, I'm open for suggestions :)

CC: Andrey Vagin <avagin at openvz.org>
Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 test/zdtm/lib/ns.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/test/zdtm/lib/ns.c b/test/zdtm/lib/ns.c
index 8c67abe..9b0614a 100644
--- a/test/zdtm/lib/ns.c
+++ b/test/zdtm/lib/ns.c
@@ -5,6 +5,7 @@
 #include <grp.h>
 #include <string.h>
 #include <errno.h>
+#include <stdbool.h>
 #include <sys/mount.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -251,6 +252,7 @@ int ns_init(int argc, char **argv)
 	int ret, fd, status_pipe = STATUS_FD;
 	char buf[128], *x;
 	pid_t pid;
+	bool reap;
 
 	ret = fcntl(status_pipe, F_SETFD, FD_CLOEXEC);
 	if (ret == -1) {
@@ -258,9 +260,12 @@ int ns_init(int argc, char **argv)
 		exit(1);
 	}
 
+	reap = getenv("ZDTM_NOREAP") == NULL;
+
 	sigemptyset(&sa.sa_mask);
 	sigaddset(&sa.sa_mask, SIGTERM);
-	sigaddset(&sa.sa_mask, SIGCHLD);
+	if (reap)
+		sigaddset(&sa.sa_mask, SIGCHLD);
 
 	if (sigaction(SIGTERM, &sa, NULL)) {
 		fprintf(stderr, "Can't set SIGTERM handler: %m\n");
@@ -290,12 +295,12 @@ int ns_init(int argc, char **argv)
 
 	show_ps();
 
-	if (sigaction(SIGCHLD, &sa, NULL)) {
+	if (reap && sigaction(SIGCHLD, &sa, NULL)) {
 		fprintf(stderr, "Can't set SIGCHLD handler: %m\n");
 		exit(1);
 	}
 
-	while (1) {
+	while (reap && 1) {
 		int status;
 
 		pid = waitpid(-1, &status, WNOHANG);
-- 
2.7.4



More information about the CRIU mailing list