[CRIU] [PATCH v2 3/5] tests: add a test for the case when there is a helper with a zombie child

Andrew Vagin avagin at virtuozzo.com
Thu Jul 7 15:43:33 PDT 2016


On Wed, Jun 29, 2016 at 03:18:24PM -0600, Tycho Andersen wrote:
> On Wed, Jun 29, 2016 at 03:11:42PM -0600, Tycho Andersen wrote:
> > Hmm, yep. Actually we can't wait() here because it's not a child, but
> > we should wait for it above, nice catch. I'll resend, thanks!
> 
> See attached.

Acked-by: Andrew Vagin <avagin at virtuozzo.com>
> 
> Tycho

> From 2f06e30206a3f78ecb8ddff38f5687ea760a88d6 Mon Sep 17 00:00:00 2001
> From: Tycho Andersen <tycho.andersen at canonical.com>
> Date: Thu, 23 Jun 2016 01:59:13 +0000
> Subject: [PATCH 3/5] tests: add a test for the case when there is a helper
>  with a zombie child
> 
> v2: drop /bin/ps from test deps
> v3: wait for the zombie to make sure it exits
> 
> Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
> ---
>  test/zdtm/.gitignore                      |   1 +
>  test/zdtm/static/Makefile                 |   1 +
>  test/zdtm/static/helper_zombie_child.c    | 109 ++++++++++++++++++++++++++++++
>  test/zdtm/static/helper_zombie_child.desc |   1 +
>  4 files changed, 112 insertions(+)
>  create mode 100644 test/zdtm/static/helper_zombie_child.c
>  create mode 100644 test/zdtm/static/helper_zombie_child.desc
> 
> diff --git a/test/zdtm/.gitignore b/test/zdtm/.gitignore
> index 85e39a2..ec3c9d4 100644
> --- a/test/zdtm/.gitignore
> +++ b/test/zdtm/.gitignore
> @@ -55,6 +55,7 @@
>  /static/grow_map
>  /static/grow_map02
>  /static/grow_map03
> +/static/helper_zombie_child
>  /static/inotify00
>  /static/inotify01
>  /static/inotify02
> diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
> index 407a80f..1f465f0 100644
> --- a/test/zdtm/static/Makefile
> +++ b/test/zdtm/static/Makefile
> @@ -150,6 +150,7 @@ TST_NOFILE	=				\
>  		oom_score_adj			\
>  		loginuid			\
>  		cgroupns			\
> +		helper_zombie_child		\
>  #		jobctl00			\
>  
>  TST_FILE	=				\
> diff --git a/test/zdtm/static/helper_zombie_child.c b/test/zdtm/static/helper_zombie_child.c
> new file mode 100644
> index 0000000..1822718
> --- /dev/null
> +++ b/test/zdtm/static/helper_zombie_child.c
> @@ -0,0 +1,109 @@
> +#define _GNU_SOURCE
> +#include <unistd.h>
> +#include <stdlib.h>
> +#include <stdbool.h>
> +#include <signal.h>
> +#include <stddef.h>
> +#include <sys/types.h>
> +#include <sys/socket.h>
> +#include <sys/wait.h>
> +#include <sys/prctl.h>
> +
> +#include "zdtmtst.h"
> +
> +const char *test_doc	= "Check that a zombie with a helper parent is restored";
> +const char *test_author	= "Tycho Andersen <tycho.andersen at canonical.com>";
> +
> +void setsid_and_fork(int sk)
> +{
> +	pid_t zombie;
> +
> +	setsid();
> +
> +	zombie = fork();
> +	if (zombie < 0) {
> +		fail("fork");
> +		exit(1);
> +	}
> +
> +	if (zombie == 0)
> +		exit(0);
> +
> +	if (waitid(P_PID, zombie, NULL, WNOWAIT | WEXITED) < 0) {
> +		fail("waitid");
> +		exit(1);
> +	}
> +
> +	if (write(sk, &zombie, sizeof(zombie)) != sizeof(zombie)) {
> +		fail("write");
> +		exit(1);
> +	}
> +
> +	close(sk);
> +
> +	exit(0);
> +}
> +
> +int main(int argc, char **argv)
> +{
> +	pid_t pid, zombie;
> +	int status, sk_pair[2];
> +
> +	if (setenv("ZDTM_NOREAP", "1", 1) < 0) {
> +		fail("setenv");
> +		return 1;
> +	}
> +
> +	test_init(argc, argv);
> +
> +	if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sk_pair)) {
> +		pr_perror("socketpair");
> +		return 1;
> +	}
> +
> +	pid = fork();
> +	if (pid < 0) {
> +		fail("fork");
> +		return 1;
> +	}
> +
> +	if (pid == 0) {
> +		close(sk_pair[0]);
> +		setsid_and_fork(sk_pair[1]);
> +	}
> +
> +	close(sk_pair[1]);
> +
> +	if (read(sk_pair[0], &zombie, sizeof(zombie)) != sizeof(zombie)) {
> +		fail("read");
> +		kill(pid, SIGKILL);
> +		return 1;
> +	}
> +
> +	if (waitpid(pid, &status, 0) < 0) {
> +		fail("waitpid");
> +		return 1;
> +	}
> +
> +	if (!WIFEXITED(status) || WEXITSTATUS(status)) {
> +		fail("setsid_and_fork");
> +		return 1;
> +	}
> +
> +	if (kill(zombie, 0) < 0) {
> +		fail("zombie already dead?");
> +		return 1;
> +	}
> +
> +	test_daemon();
> +	test_waitsig();
> +
> +	/* XXX: we don't restore zombies with the right uid right now; they're all root */
> +	if (kill(zombie, 0) < 0 && errno != EPERM) {
> +		fail("zombie didn't survive restore");
> +		return 1;
> +	}
> +
> +	pass();
> +	return 0;
> +}
> diff --git a/test/zdtm/static/helper_zombie_child.desc b/test/zdtm/static/helper_zombie_child.desc
> new file mode 100644
> index 0000000..6c4afe5
> --- /dev/null
> +++ b/test/zdtm/static/helper_zombie_child.desc
> @@ -0,0 +1 @@
> +{'flavor': 'ns uns'}
> -- 
> 2.7.4
> 



More information about the CRIU mailing list