[LTP] [PATCH] safe_mmap: Avoid using TDEBUG before IPC is initialized

Li Wang liwang@redhat.com
Mon Jun 16 16:02:09 CEST 2025


On Mon, Jun 16, 2025 at 8:29 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> Hi!
> > Notes:
> >     I admit that this removal may result in the loss of early debug
> >     output from the LTP library. However, after reviewing the codebase,
> >     it appears that this was the only place using TDEBUG during early
> >     initialization, so removing it simplifies the behavior without
> >     significant loss of functionality.
> >
> >     But, if someone argues that we need this, I guess we can add a
> >     macro tst_early_debug(fmt, ...) to replace the tst_res_(TDEBUG, ...).
>
> Actually I was thinking of adding TDEBUG messages into more
> SAFE_MACROS() in order to make test debugging easier.
>
> Maybe we can just skip the TDEBUG messages for the test library process
> I do not think that we are interested SAFE_MACROS() being called from
> there.
>

Good point, maybe refine the patch like:

--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -476,8 +476,22 @@ void tst_res_(const char *file, const int lineno, int
ttype,
 {
        va_list va;

-       if (ttype == TDEBUG && context && !context->tdebug)
-               return;
+       /*
+        * Suppress TDEBUG output in these cases:
+        * 1. No context available (e.g., called before IPC initialization)
+        * 2. Called from the library process, unless explicitly enabled
+        * 3. Debug output is not enabled (context->tdebug == 0)
+        */
+       if (ttype == TDEBUG) {
+               if (!context)
+                       return;
+
+               if (getpid() == context->lib_pid)
+                       return;
+
+               if (!context->tdebug)
+                       return;
+       }

        va_start(va, fmt);
        tst_vres_(file, lineno, ttype, fmt, va);


-- 
Regards,
Li Wang


More information about the ltp mailing list