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

Li Wang liwang@redhat.com
Thu Jun 12 05:42:29 CEST 2025


After commit bf9589d5bd ("lib: move test infrastructure states into a shared context structure"),
each test began printing unexpected TDEBUG messages like:

  tst_test.c:142: TDEBUG: mmap((nil), 4096, PROT_READ | PROT_WRITE(3), 1, 3, 0)
  ...
  tst_test.c:199: TDEBUG: mmap((nil), 4096, PROT_READ | PROT_WRITE(3), 1, 3, 0)

This happens because the logic in tst_res_():

  if (ttype == TDEBUG && context && !context->tdebug)

allows TDEBUG messages to be printed even the context is not yet initialized.
During early test setup (such as in SAFE_MMAP), the shared context may
not be initialized yet, causing debug logs to be emitted unintentionally.

This patch removes the TDEBUG logging from SAFE_MMAP to avoid these
misleading logs during early initialization.

Follow-up: commit bf9589d5bd ("lib: move test infrastructure states into a shared context structure")
Signed-off-by: Li Wang <liwang@redhat.com>
---

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, ...).

 include/tst_safe_macros_inline.h | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/include/tst_safe_macros_inline.h b/include/tst_safe_macros_inline.h
index 15b756860..15500b20a 100644
--- a/include/tst_safe_macros_inline.h
+++ b/include/tst_safe_macros_inline.h
@@ -237,10 +237,6 @@ static inline void *safe_mmap(const char *file, const int lineno,
 
 	tst_prot_to_str(prot, prot_buf);
 
-	tst_res_(file, lineno, TDEBUG,
-		"mmap(%p, %zu, %s(%x), %d, %d, %lld)",
-		addr, length, prot_buf, prot, flags, fd, (long long int)offset);
-
 	rval = mmap(addr, length, prot, flags, fd, offset);
 	if (rval == MAP_FAILED) {
 		tst_brk_(file, lineno, TBROK | TERRNO,
-- 
2.49.0



More information about the ltp mailing list