mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-05 09:17:44 +03:00
meson: merge our two valgrind configuration conditions into one
Most of the support for valgrind was under HAVE_VALGRIND_VALGRIND_H, i.e. we would enable if the valgrind headers were found. The operations then we be conditionalized on RUNNING_UNDER_VALGRIND. But in a few places we had code which was conditionalized on VALGRIND, i.e. the config option. I noticed because I compiled with -Dvalgrind=true on a machine that didn't have valgrind.h, and the build failed because RUNNING_UNDER_VALGRIND was not defined. My first idea was to add a check that the header is present if the option is set, but it seems better to just remove the option. The code to support valgrind is trivial, and if we're !RUNNING_UNDER_VALGRIND, it has negligible cost. And the case of running under valgrind is always some special testing/debugging mode, so we should just do those extra steps to make valgrind output cleaner. Removing the option makes things simpler and we don't have to think if something should be covered by the one or the other configuration bit. I had a vague recollection that in some places we used -Dvalgrind=true not for valgrind support, but to enable additional cleanup under other sanitizers. But that code would fail to build without the valgrind headers anyway, so I'm not sure if that was still used. If there are uses like that, we can extend the condition for cleanup_pools().
This commit is contained in:
parent
3f275dcb84
commit
50b35193ec
12
README
12
README
@ -403,12 +403,12 @@ WARNINGS and TAINT FLAGS:
|
|||||||
See org.freedesktop.systemd1(5) for more information.
|
See org.freedesktop.systemd1(5) for more information.
|
||||||
|
|
||||||
VALGRIND:
|
VALGRIND:
|
||||||
To run systemd under valgrind, compile with meson option
|
To run systemd under valgrind, compile systemd with the valgrind
|
||||||
-Dvalgrind=true and have valgrind development headers installed
|
development headers available (i.e. valgrind-devel or equivalent).
|
||||||
(i.e. valgrind-devel or equivalent). Otherwise, false positives will be
|
Otherwise, false positives will be triggered by code which violates
|
||||||
triggered by code which violates some rules but is actually safe. Note
|
some rules but is actually safe. Note that valgrind generates nice
|
||||||
that valgrind generates nice output only on exit(), hence on shutdown
|
output only on exit(), hence on shutdown we don't execve()
|
||||||
we don't execve() systemd-shutdown.
|
systemd-shutdown.
|
||||||
|
|
||||||
STABLE BRANCHES AND BACKPORTS:
|
STABLE BRANCHES AND BACKPORTS:
|
||||||
Stable branches with backported patches are available in the
|
Stable branches with backported patches are available in the
|
||||||
|
@ -1020,8 +1020,6 @@ endforeach
|
|||||||
conf.set10('ENABLE_DEBUG_HASHMAP', enable_debug_hashmap)
|
conf.set10('ENABLE_DEBUG_HASHMAP', enable_debug_hashmap)
|
||||||
conf.set10('ENABLE_DEBUG_MMAP_CACHE', enable_debug_mmap_cache)
|
conf.set10('ENABLE_DEBUG_MMAP_CACHE', enable_debug_mmap_cache)
|
||||||
conf.set10('ENABLE_DEBUG_SIPHASH', enable_debug_siphash)
|
conf.set10('ENABLE_DEBUG_SIPHASH', enable_debug_siphash)
|
||||||
|
|
||||||
conf.set10('VALGRIND', get_option('valgrind'))
|
|
||||||
conf.set10('LOG_TRACE', get_option('log-trace'))
|
conf.set10('LOG_TRACE', get_option('log-trace'))
|
||||||
|
|
||||||
default_user_path = get_option('user-path')
|
default_user_path = get_option('user-path')
|
||||||
@ -4608,7 +4606,6 @@ foreach tuple : [
|
|||||||
['debug hashmap'],
|
['debug hashmap'],
|
||||||
['debug mmap cache'],
|
['debug mmap cache'],
|
||||||
['debug siphash'],
|
['debug siphash'],
|
||||||
['valgrind', conf.get('VALGRIND') == 1],
|
|
||||||
['trace logging', conf.get('LOG_TRACE') == 1],
|
['trace logging', conf.get('LOG_TRACE') == 1],
|
||||||
['install tests', install_tests],
|
['install tests', install_tests],
|
||||||
['link-udev-shared', get_option('link-udev-shared')],
|
['link-udev-shared', get_option('link-udev-shared')],
|
||||||
|
@ -79,8 +79,6 @@ option('bump-proc-sys-fs-file-max', type : 'boolean',
|
|||||||
description : 'bump /proc/sys/fs/file-max to LONG_MAX')
|
description : 'bump /proc/sys/fs/file-max to LONG_MAX')
|
||||||
option('bump-proc-sys-fs-nr-open', type : 'boolean',
|
option('bump-proc-sys-fs-nr-open', type : 'boolean',
|
||||||
description : 'bump /proc/sys/fs/nr_open to INT_MAX')
|
description : 'bump /proc/sys/fs/nr_open to INT_MAX')
|
||||||
option('valgrind', type : 'boolean', value : false,
|
|
||||||
description : 'do extra operations to avoid valgrind warnings')
|
|
||||||
option('log-trace', type : 'boolean', value : false,
|
option('log-trace', type : 'boolean', value : false,
|
||||||
description : 'enable low level debug logging')
|
description : 'enable low level debug logging')
|
||||||
option('user-path', type : 'string',
|
option('user-path', type : 'string',
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#if HAVE_VALGRIND_VALGRIND_H
|
||||||
|
# include <valgrind/valgrind.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "fileio.h"
|
#include "fileio.h"
|
||||||
@ -295,10 +298,11 @@ void hashmap_trim_pools(void) {
|
|||||||
mempool_trim(&ordered_hashmap_pool);
|
mempool_trim(&ordered_hashmap_pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if VALGRIND
|
#if HAVE_VALGRIND_VALGRIND_H
|
||||||
_destructor_ static void cleanup_pools(void) {
|
_destructor_ static void cleanup_pools(void) {
|
||||||
/* Be nice to valgrind */
|
/* Be nice to valgrind */
|
||||||
hashmap_trim_pools();
|
if (RUNNING_ON_VALGRIND)
|
||||||
|
hashmap_trim_pools();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include <seccomp.h>
|
#include <seccomp.h>
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_VALGRIND_VALGRIND_H
|
#if HAVE_VALGRIND_VALGRIND_H
|
||||||
#include <valgrind/valgrind.h>
|
# include <valgrind/valgrind.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "sd-bus.h"
|
#include "sd-bus.h"
|
||||||
@ -1866,8 +1866,8 @@ static int do_reexecute(
|
|||||||
assert(i <= args_size);
|
assert(i <= args_size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We want valgrind to print its memory usage summary before reexecution. Valgrind won't do
|
* We want valgrind to print its memory usage summary before reexecution. Valgrind won't do
|
||||||
* this is on its own on exec(), but it will do it on exit(). Hence, to ensure we get a
|
* this is on its own on exec(), but it will do it on exit(). Hence, to ensure we get a
|
||||||
* summary here, fork() off a child, let it exit() cleanly, so that it prints the summary,
|
* summary here, fork() off a child, let it exit() cleanly, so that it prints the summary,
|
||||||
* and wait() for it in the parent, before proceeding into the exec().
|
* and wait() for it in the parent, before proceeding into the exec().
|
||||||
*/
|
*/
|
||||||
|
@ -9,6 +9,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#if HAVE_VALGRIND_VALGRIND_H
|
||||||
|
# include <valgrind/valgrind.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "sd-dhcp-client.h"
|
#include "sd-dhcp-client.h"
|
||||||
#include "sd-event.h"
|
#include "sd-event.h"
|
||||||
@ -546,11 +549,12 @@ int main(int argc, char *argv[]) {
|
|||||||
test_discover_message(e);
|
test_discover_message(e);
|
||||||
test_addr_acq(e);
|
test_addr_acq(e);
|
||||||
|
|
||||||
#if VALGRIND
|
#if HAVE_VALGRIND_VALGRIND_H
|
||||||
/* Make sure the async_close thread has finished.
|
/* Make sure the async_close thread has finished.
|
||||||
* valgrind would report some of the phread_* structures
|
* valgrind would report some of the phread_* structures
|
||||||
* as not cleaned up properly. */
|
* as not cleaned up properly. */
|
||||||
sleep(1);
|
if (RUNNING_ON_VALGRIND)
|
||||||
|
sleep(1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#if HAVE_VALGRIND_VALGRIND_H
|
#if HAVE_VALGRIND_VALGRIND_H
|
||||||
#include <valgrind/valgrind.h>
|
# include <valgrind/valgrind.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SD_JOURNAL_SUPPRESS_LOCATION
|
#define SD_JOURNAL_SUPPRESS_LOCATION
|
||||||
@ -77,9 +77,9 @@ int journal_fd_nonblock(bool nonblock) {
|
|||||||
return fd_nonblock(r, nonblock);
|
return fd_nonblock(r, nonblock);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if VALGRIND
|
|
||||||
void close_journal_fd(void) {
|
void close_journal_fd(void) {
|
||||||
/* Be nice to valgrind. This is not atomic. This must be used only in tests. */
|
#if HAVE_VALGRIND_VALGRIND_H
|
||||||
|
/* Be nice to valgrind. This is not atomic, so it is useful mainly for debugging. */
|
||||||
|
|
||||||
if (!RUNNING_ON_VALGRIND)
|
if (!RUNNING_ON_VALGRIND)
|
||||||
return;
|
return;
|
||||||
@ -92,8 +92,8 @@ void close_journal_fd(void) {
|
|||||||
|
|
||||||
safe_close(fd_plus_one - 1);
|
safe_close(fd_plus_one - 1);
|
||||||
fd_plus_one = 0;
|
fd_plus_one = 0;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
_public_ int sd_journal_print(int priority, const char *format, ...) {
|
_public_ int sd_journal_print(int priority, const char *format, ...) {
|
||||||
int r;
|
int r;
|
||||||
|
@ -4,9 +4,4 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
int journal_fd_nonblock(bool nonblock);
|
int journal_fd_nonblock(bool nonblock);
|
||||||
|
|
||||||
#if VALGRIND
|
|
||||||
void close_journal_fd(void);
|
void close_journal_fd(void);
|
||||||
#else
|
|
||||||
static inline void close_journal_fd(void) {}
|
|
||||||
#endif
|
|
||||||
|
@ -320,7 +320,9 @@ uint32_t jenkins_hashlittle( const void *key, size_t length, uint32_t initval)
|
|||||||
* still catch it and complain. The masking trick does make the hash
|
* still catch it and complain. The masking trick does make the hash
|
||||||
* noticeably faster for short strings (like English words).
|
* noticeably faster for short strings (like English words).
|
||||||
*/
|
*/
|
||||||
#if !VALGRIND && !HAS_FEATURE_ADDRESS_SANITIZER && !HAS_FEATURE_MEMORY_SANITIZER
|
#define VALGRIND_LIKE (HAVE_VALGRIND_VALGRIND_H || HAS_FEATURE_ADDRESS_SANITIZER || HAS_FEATURE_MEMORY_SANITIZER)
|
||||||
|
|
||||||
|
#if !VALGRIND_LIKE
|
||||||
|
|
||||||
switch(length)
|
switch(length)
|
||||||
{
|
{
|
||||||
@ -505,7 +507,7 @@ void jenkins_hashlittle2(
|
|||||||
* still catch it and complain. The masking trick does make the hash
|
* still catch it and complain. The masking trick does make the hash
|
||||||
* noticeably faster for short strings (like English words).
|
* noticeably faster for short strings (like English words).
|
||||||
*/
|
*/
|
||||||
#if !VALGRIND && !HAS_FEATURE_ADDRESS_SANITIZER && !HAS_FEATURE_MEMORY_SANITIZER
|
#if !VALGRIND_LIKE
|
||||||
|
|
||||||
switch(length)
|
switch(length)
|
||||||
{
|
{
|
||||||
@ -681,7 +683,7 @@ uint32_t jenkins_hashbig( const void *key, size_t length, uint32_t initval)
|
|||||||
* still catch it and complain. The masking trick does make the hash
|
* still catch it and complain. The masking trick does make the hash
|
||||||
* noticeably faster for short strings (like English words).
|
* noticeably faster for short strings (like English words).
|
||||||
*/
|
*/
|
||||||
#if !VALGRIND && !HAS_FEATURE_ADDRESS_SANITIZER && !HAS_FEATURE_MEMORY_SANITIZER
|
#if !VALGRIND_LIKE
|
||||||
|
|
||||||
switch(length)
|
switch(length)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user