test: remap_dead_pid.c: Fix child PID not being printed

Submitted by Vitaly Ostrosablin on July 20, 2017, 3:04 p.m.

Details

Message ID 20170720150401.13886-1-vostrosablin@virtuozzo.com
State Accepted
Series "test: remap_dead_pid.c: Fix child PID not being printed"
Headers show

Commit Message

Vitaly Ostrosablin July 20, 2017, 3:04 p.m.
There's two issues with this code:

1. Child task is killed by parent faster, than it could print the line.
2. Even if it had time to print it - there would always be 0, because
it's called from child process.

Obviously, this print was meant to be in parent process. So, let's move
it there.

Signed-off-by: Vitaly Ostrosablin <vostrosablin@virtuozzo.com>
---
 test/zdtm/static/remap_dead_pid.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/test/zdtm/static/remap_dead_pid.c b/test/zdtm/static/remap_dead_pid.c
index 1ee61a9d0..261c591b7 100644
--- a/test/zdtm/static/remap_dead_pid.c
+++ b/test/zdtm/static/remap_dead_pid.c
@@ -35,12 +35,13 @@  int main(int argc, char **argv)
 	}
 
 	if (pid == 0) {
-		test_msg("child is %d\n", pid);
 		/* Child process just sleeps until it is killed. All we need
 		 * here is a process to open the mountinfo of. */
 		while(1)
 			sleep(10);
 	} else {
+		test_msg("child is %d\n", pid);
+
 		int fd, ret;
 		char path[PATH_MAX];
 		pid_t result;

Comments

Andrey Vagin July 24, 2017, 10:35 p.m.
Applied, thanks!

On Thu, Jul 20, 2017 at 06:04:01PM +0300, Vitaly Ostrosablin wrote:
> There's two issues with this code:
> 
> 1. Child task is killed by parent faster, than it could print the line.
> 2. Even if it had time to print it - there would always be 0, because
> it's called from child process.
> 
> Obviously, this print was meant to be in parent process. So, let's move
> it there.
> 
> Signed-off-by: Vitaly Ostrosablin <vostrosablin@virtuozzo.com>
> ---
>  test/zdtm/static/remap_dead_pid.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/test/zdtm/static/remap_dead_pid.c b/test/zdtm/static/remap_dead_pid.c
> index 1ee61a9d0..261c591b7 100644
> --- a/test/zdtm/static/remap_dead_pid.c
> +++ b/test/zdtm/static/remap_dead_pid.c
> @@ -35,12 +35,13 @@ int main(int argc, char **argv)
>  	}
>  
>  	if (pid == 0) {
> -		test_msg("child is %d\n", pid);
>  		/* Child process just sleeps until it is killed. All we need
>  		 * here is a process to open the mountinfo of. */
>  		while(1)
>  			sleep(10);
>  	} else {
> +		test_msg("child is %d\n", pid);
> +
>  		int fd, ret;
>  		char path[PATH_MAX];
>  		pid_t result;
> -- 
> 2.13.3
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu