[CRIU] [PATCH] zdtm: pty00 -- Count for SIGHUP

Andrew Vagin avagin at parallels.com
Fri Aug 15 05:41:30 PDT 2014


On Fri, Aug 15, 2014 at 04:32:57PM +0400, Cyrill Gorcunov wrote:
> Just to make sure we're not loosing signals
> after restore.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  test/zdtm/live/static/pty00.c | 27 +++++++++++++++++++++++++--
>  1 file changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/test/zdtm/live/static/pty00.c b/test/zdtm/live/static/pty00.c
> index 260fa407b0a5..bb6893b838bc 100644
> --- a/test/zdtm/live/static/pty00.c
> +++ b/test/zdtm/live/static/pty00.c
> @@ -12,6 +12,13 @@
>  const char *test_doc	= "Check, that pseudoterminals are restored";
>  const char *test_author	= "Andrey Vagin <avagin at openvz.org>";
>  
> +static unsigned int nr_sighups;
> +
> +static void signal_handler_sighup(int signum)
> +{
> +	nr_sighups++;
> +}
> +
>  int main(int argc, char ** argv)
>  {
>  	int fdm, fds, ret;
> @@ -19,6 +26,11 @@ int main(int argc, char ** argv)
>  	char buf[10];
>  	const char teststr[] = "hello\n";
>  
> +	struct sigaction sa = {
> +		.sa_handler = signal_handler_sighup,
> +		.sa_flags = 0,
> +	};
> +
>  	test_init(argc, argv);
>  
>  	fdm = open("/dev/ptmx", O_RDWR);
> @@ -54,7 +66,14 @@ int main(int argc, char ** argv)
>  
>  	test_waitsig();
>  
> -	signal(SIGHUP, SIG_IGN);
> +	/*
> +	 * On closing control terminal we're expecting to
> +	 * receive SIGHUP, so make sure it's delivered.
> +	 */
> +	if (sigaction(SIGHUP, &sa, 0)) {
> +		fail("sigaction failed\n");
> +		return 1;
> +	}
>  
>  	/* Check connectivity */
>  	ret = write(fdm, teststr, sizeof(teststr) - 1);
> @@ -77,7 +96,11 @@ int main(int argc, char ** argv)

I think we should set sigaction here. Otherwise you don't check that a
signal is received in a right place.

>  	close(fdm);
>  	close(fds);
>  
> -	pass();
> +	if (nr_sighups != 1) {
> +		fail("Expected 1 SIGHUP but got %d", nr_sighups);
> +		return 1;
> +	} else
> +		pass();
>  
>  	return 0;
>  }
> -- 
> 1.9.3
> 


More information about the CRIU mailing list