diff mbox series

lib/tst_test.c: Bugfix for heartbeat

Message ID 20210323135604.24504-1-zhaogongyi@huawei.com
State Changes Requested
Headers show
Series lib/tst_test.c: Bugfix for heartbeat | expand

Commit Message

Zhao Gongyi March 23, 2021, 1:56 p.m. UTC
When main process has been killed, its son process will be reaped by
init, and son process will send SIGUSR1 to the init process.

In busybox, send SIGUSR1 to the init process will trigger shutdown.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 lib/tst_test.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

--
2.17.1

Comments

Cyril Hrubis April 12, 2021, 3:10 p.m. UTC | #1
Hi!
> When main process has been killed, its son process will be reaped by
> init, and son process will send SIGUSR1 to the init process.
> 
> In busybox, send SIGUSR1 to the init process will trigger shutdown.
> 
> Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> ---
>  lib/tst_test.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index 45753d1ca..91dfc6bf9 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -1156,7 +1156,15 @@ static void heartbeat(void)
>  	if (tst_clock_gettime(CLOCK_MONOTONIC, &tst_start_time))
>  		tst_res(TWARN | TERRNO, "tst_clock_gettime() failed");
> 
> -	kill(getppid(), SIGUSR1);
> +	if (getppid() == 1) {
> +		tst_res(TFAIL, "Main test process might have exit!");
                         ^
			 This should be TBROK I guess.
> +		/*
> +		 * We need kill the task group immediately since the
> +		 * main process has exit.
> +		 */
> +		kill(0, SIGKILL);

Shouldn't we call exit here? There is no point in continuing once we
reached this point.

> +	} else
> +		kill(getppid(), SIGUSR1);
>  }
> 
>  static void testrun(void)
> --
> 2.17.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp
Petr Vorel April 15, 2021, 7:52 a.m. UTC | #2
Hi,

LGTM.
Reviewed-by: Petr Vorel <pvorel@suse.cz>

> When main process has been killed, its son process will be reaped by
=> nit: son/child

> init, and son process will send SIGUSR1 to the init process.

Kind regards,
Petr
Cyril Hrubis April 15, 2021, 11:31 a.m. UTC | #3
Hi!
There is a v2 already, can you have a look?
Petr Vorel April 15, 2021, 2:03 p.m. UTC | #4
> Hi!
> There is a v2 already, can you have a look?
I'm sorry to reply to the old one.  I looked at both versions, but meant to sent
review to v2.

Kind regards,
Petr
diff mbox series

Patch

diff --git a/lib/tst_test.c b/lib/tst_test.c
index 45753d1ca..91dfc6bf9 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1156,7 +1156,15 @@  static void heartbeat(void)
 	if (tst_clock_gettime(CLOCK_MONOTONIC, &tst_start_time))
 		tst_res(TWARN | TERRNO, "tst_clock_gettime() failed");

-	kill(getppid(), SIGUSR1);
+	if (getppid() == 1) {
+		tst_res(TFAIL, "Main test process might have exit!");
+		/*
+		 * We need kill the task group immediately since the
+		 * main process has exit.
+		 */
+		kill(0, SIGKILL);
+	} else
+		kill(getppid(), SIGUSR1);
 }

 static void testrun(void)