From 2eaabf845f503cda07082146485c798fee5f31fd Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Sat, 31 Dec 2011 00:00:36 +0530 Subject: [PATCH] core: Detect valgrind for real Instead of depending on an environment variable, we use Valgrind's macros to detect whether we're running inside Valgrind. https://bugs.freedesktop.org/show_bug.cgi?id=42942 --- configure.ac | 1 + src/pulsecore/core-util.c | 18 +++++++++--------- src/pulsecore/core-util.h | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index c16aaa9..badfd5b 100644 --- a/configure.ac +++ b/configure.ac @@ -577,6 +577,7 @@ fi #### Valgrind (optional) #### +AC_CHECK_HEADERS_ONCE([valgrind/valgrind.h]) AC_CHECK_HEADERS_ONCE([valgrind/memcheck.h]) #### json parsing #### diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index 1aa5a9a..d6979ec 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -121,6 +121,10 @@ #include #endif +#ifdef HAVE_VALGRIND_VALGRIND_H +#include +#endif + #include #include #include @@ -2772,18 +2776,14 @@ char *pa_uname_string(void) { #endif } -#ifdef HAVE_VALGRIND_MEMCHECK_H +#ifdef HAVE_VALGRIND_VALGRIND_H pa_bool_t pa_in_valgrind(void) { - static int b = 0; - - /* To make heisenbugs a bit simpler to find we check for $VALGRIND - * here instead of really checking whether we run in valgrind or - * not. */ + static int b = -1; - if (b < 1) - b = getenv("VALGRIND") ? 2 : 1; + if (b < 0) + b = RUNNING_ON_VALGRIND; - return b > 1; + return b > 0; } #endif diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index 4a1c096..15740cb 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -213,7 +213,7 @@ char *pa_machine_id(void); char *pa_session_id(void); char *pa_uname_string(void); -#ifdef HAVE_VALGRIND_MEMCHECK_H +#ifdef HAVE_VALGRIND_VALGRIND_H pa_bool_t pa_in_valgrind(void); #else static inline pa_bool_t pa_in_valgrind(void) { -- 1.7.8.1