[LTP] [PATCH] lib/tst_test.c: Fix tst_brk() handling

Cyril Hrubis chrubis@suse.cz
Fri Apr 4 14:04:35 CEST 2025


Hi!
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index c6395a5eb..6b1100b09 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -407,7 +407,8 @@ void tst_vbrk_(const char *file, const int lineno, int ttype, const char *fmt,
>          * current process.
>          */
>         if (TTYPE_RESULT(ttype) == TBROK) {
> -               tst_atomic_inc(&results->abort_flag);
> +               if (results)
> +                       tst_atomic_inc(&results->abort_flag);
> 
>                 /*
>                  * If TBROK was called from one of the child processes we kill
> 

And it's a bit more complex we also need to make sure to exit properly
when tst_brk() was called before the library was initialized, so we also
need:

diff --git a/lib/tst_test.c b/lib/tst_test.c
index 758e62823..d19908d94 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -386,6 +386,14 @@ void tst_vbrk_(const char *file, const int lineno, int ttype, const char *fmt,
               va_list va)
 {
        print_result(file, lineno, ttype, fmt, va);
+
+       /*
+        * If tst_brk() is called from some of the C helpers even before the
+        * library was initialized, just exit.
+        */
+       if (!lib_pid)
+               exit(TTYPE_RESULT(ttype));
+
        update_results(TTYPE_RESULT(ttype));

        /*
@@ -415,7 +423,7 @@ void tst_vbrk_(const char *file, const int lineno, int ttype, const char *fmt,
                 * the main test process. That in turn triggers the code that
                 * kills leftover children once the main test process did exit.
                 */
-               if (tst_getpid() != main_pid) {
+               if (main_pid && tst_getpid() != main_pid) {
                        tst_res(TINFO, "Child process reported TBROK killing the test");
                        kill(main_pid, SIGKILL);
                }


I will send v2 later on.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list