From 018c562eab6d0d431c1675af6740baaa915611c3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 13 May 2018 22:28:24 +0200 Subject: [PATCH] Turn VALGRIND variable into a meson configuration switch Configuration through environment variable is inconvenient with meson, because they cannot be convieniently changed and/or are not preserved during reconfiguration (https://github.com/mesonbuild/meson/issues/1503). This adds -Dvalgrind=true/false, which has the advantage that it can be set at any time with meson configure -Dvalgrind=... and ninja will rebuild targets as necessary. Additional minor advantages are better consistency with the options for hashmap debugging, and typo avoidance with '#if' instead of '#ifdef'. --- meson.build | 4 ++++ meson_options.txt | 2 ++ src/basic/hashmap.c | 2 +- src/basic/mempool.c | 2 +- src/basic/mempool.h | 2 +- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 6533e38c7..c18b5b496 100644 --- a/meson.build +++ b/meson.build @@ -905,6 +905,8 @@ conf.set10('ENABLE_DEBUG_MMAP_CACHE', enable_debug_mmap_cache) conf.set10('ENABLE_DEBUG_ELOGIND', enable_debug_elogind) #endif // 1 +conf.set10('VALGRIND', get_option('valgrind')) + ##################################################################### threads = dependency('threads') @@ -1909,6 +1911,7 @@ exe = executable('elogind-inhibit', public_programs += [exe] executable('elogind-user-runtime-dir', executable('elogind-user-runtime-dir', +executable('elogind-user-runtime-dir', executable('elogind-user-runtime-dir', user_runtime_dir_sources, include_directories : includes, @@ -3277,6 +3280,7 @@ foreach tuple : [ # ['adm group', get_option('adm-group')], # ['wheel group', get_option('wheel-group')], # ['gshadow'], +# ['valgrind', conf.get('VALGRIND') == 1], #else ['debug elogind'], #endif // 0 diff --git a/meson_options.txt b/meson_options.txt index fe8a5c972..f39bed270 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -74,6 +74,8 @@ option('kexec-path', type : 'string', description : 'path to kexec') # description : 'enable extra debugging') # option('memory-accounting-default', type : 'boolean', # description : 'enable MemoryAccounting= by default') +# option('valgrind', type : 'boolean', value : false, +# description : 'do extra operations to avoid valgrind warnings') #else option('debug', type : 'string', description : 'enable extra debugging (elogind,hashmap,mmap-cache)') diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c index a70fd667c..95c15c26c 100644 --- a/src/basic/hashmap.c +++ b/src/basic/hashmap.c @@ -281,7 +281,7 @@ static const struct hashmap_type_info hashmap_type_info[_HASHMAP_TYPE_MAX] = { }, }; -#ifdef VALGRIND +#if VALGRIND __attribute__((destructor)) static void cleanup_pools(void) { _cleanup_free_ char *t = NULL; int r; diff --git a/src/basic/mempool.c b/src/basic/mempool.c index 4be4a3d38..2e55639e8 100644 --- a/src/basic/mempool.c +++ b/src/basic/mempool.c @@ -76,7 +76,7 @@ void mempool_free_tile(struct mempool *mp, void *p) { mp->freelist = p; } -#ifdef VALGRIND +#if VALGRIND void mempool_drop(struct mempool *mp) { struct pool *p = mp->first_pool; diff --git a/src/basic/mempool.h b/src/basic/mempool.h index 5322fd480..68249cd88 100644 --- a/src/basic/mempool.h +++ b/src/basic/mempool.h @@ -30,6 +30,6 @@ static struct mempool pool_name = { \ } -#ifdef VALGRIND +#if VALGRIND void mempool_drop(struct mempool *mp); #endif -- 2.30.2