From c6a37ddca438e05dcf0d0ae023f367fa28654bdd Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 25 Apr 2024 21:20:36 +0200 Subject: [PATCH] toolcontext: check runtime valgrind When reseting stream buffer - check for being run within valgrind and only in this case skip this code. Define VALGRIND_POOL was incorrectly used for this logic. --- lib/commands/toolcontext.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c index d6008cfe1..307369535 100644 --- a/lib/commands/toolcontext.c +++ b/lib/commands/toolcontext.c @@ -45,6 +45,10 @@ #include #endif +#ifdef HAVE_VALGRIND +#include +#endif + #ifdef __linux__ # include #endif @@ -1708,9 +1712,11 @@ struct cmd_context *create_toolcontext(unsigned is_clvmd, /* FIXME Make this configurable? */ reset_lvm_errno(1); -#ifndef VALGRIND_POOL /* Set in/out stream buffering before glibc */ if (set_buffering +#ifdef HAVE_VALGRIND + && !RUNNING_ON_VALGRIND /* Skipping within valgrind execution. */ +#endif #ifdef SYS_gettid /* For threaded programs no changes of streams */ /* On linux gettid() is implemented only via syscall */ @@ -1752,7 +1758,7 @@ struct cmd_context *create_toolcontext(unsigned is_clvmd, } else if (!set_buffering) /* Without buffering, must not use stdin/stdout */ init_silent(1); -#endif + /* * Environment variable LVM_SYSTEM_DIR overrides this below. */ @@ -2087,7 +2093,10 @@ void destroy_toolcontext(struct cmd_context *cmd) dm_hash_destroy(cmd->cft_def_hash); dm_device_list_destroy(&cmd->cache_dm_devs); -#ifndef VALGRIND_POOL + +#ifdef HAVE_VALGRIND + if (!RUNNING_ON_VALGRIND) /* Skipping within valgrind execution. */ +#endif if (cmd->linebuffer) { int flags; /* Reset stream buffering to defaults */ @@ -2111,7 +2120,7 @@ void destroy_toolcontext(struct cmd_context *cmd) free(cmd->linebuffer); } -#endif + destroy_config_context(cmd); lvmpolld_disconnect();