[v2,2/5] tests: add a ZDTM_NOREAP variable

Submitted by Tycho Andersen on June 29, 2016, 3:53 p.m.

Details

Message ID 1467215605-17604-2-git-send-email-tycho.andersen@canonical.com
State Rejected
Series "Series without cover letter"
Headers show

Commit Message

Tycho Andersen June 29, 2016, 3:53 p.m.
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@openvz.org>
Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
---
 test/zdtm/lib/ns.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

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);