From a5d8835c78112206bbf0812dd4cb471f803bfe88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 9 Oct 2018 16:02:55 +0200 Subject: [PATCH] mempool: only enable mempool use when linked to libsystemd-shared.so Mempool use is enabled or disabled based on the mempool_use_allowed symbol that is linked in. Should fix assert crashes in external programs caused by #9792. Replaces #10286. v2: - use two different source files instead of a gcc constructor --- meson.build | 3 +++ src/basic/mempool.c | 2 ++ src/basic/mempool.h | 2 ++ src/libsystemd/disable-mempool.c | 5 +++++ src/libsystemd/meson.build | 2 ++ src/shared/enable-mempool.c | 5 +++++ src/shared/meson.build | 1 + 7 files changed, 20 insertions(+) create mode 100644 src/libsystemd/disable-mempool.c create mode 100644 src/shared/enable-mempool.c diff --git a/meson.build b/meson.build index 1ef07ae1a3..09986d58dc 100644 --- a/meson.build +++ b/meson.build @@ -1380,6 +1380,7 @@ libjournal_core = static_library( libsystemd_sym_path = '@0@/@1@'.format(meson.current_source_dir(), libsystemd_sym) libsystemd = shared_library( 'systemd', + disable_mempool_c, version : libsystemd_version, include_directories : includes, link_args : ['-shared', @@ -1461,6 +1462,7 @@ subdir('test') test_dlopen = executable( 'test-dlopen', test_dlopen_c, + disable_mempool_c, include_directories : includes, link_with : [libbasic], dependencies : [libdl], @@ -1481,6 +1483,7 @@ foreach tuple : [['myhostname', 'ENABLE_NSS_MYHOSTNAME'], nss = shared_library( 'nss_' + module, 'src/nss-@0@/nss-@0@.c'.format(module), + disable_mempool_c, version : '2', include_directories : includes, # Note that we link NSS modules with '-z nodelete' so that mempools never get orphaned diff --git a/src/basic/mempool.c b/src/basic/mempool.c index 9f17b77e47..159c963377 100644 --- a/src/basic/mempool.c +++ b/src/basic/mempool.c @@ -78,6 +78,8 @@ bool mempool_enabled(void) { if (!is_main_thread()) return false; + if (!mempool_use_allowed) + b = false; if (b < 0) b = getenv_bool("SYSTEMD_MEMPOOL") != 0; diff --git a/src/basic/mempool.h b/src/basic/mempool.h index d3ad63628f..0eecca0f92 100644 --- a/src/basic/mempool.h +++ b/src/basic/mempool.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once +#include #include struct pool; @@ -22,6 +23,7 @@ static struct mempool pool_name = { \ .at_least = alloc_at_least, \ } +extern const bool mempool_use_allowed; bool mempool_enabled(void); #if VALGRIND diff --git a/src/libsystemd/disable-mempool.c b/src/libsystemd/disable-mempool.c new file mode 100644 index 0000000000..034bd24dc4 --- /dev/null +++ b/src/libsystemd/disable-mempool.c @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + +#include "mempool.h" + +const bool mempool_use_allowed = false; diff --git a/src/libsystemd/meson.build b/src/libsystemd/meson.build index e3716a68d8..d95406e7ac 100644 --- a/src/libsystemd/meson.build +++ b/src/libsystemd/meson.build @@ -81,6 +81,8 @@ libsystemd_sources = files(''' sd-utf8/sd-utf8.c '''.split()) + id128_sources + sd_daemon_c + sd_event_c + sd_login_c +disable_mempool_c = files('disable-mempool.c') + libsystemd_c_args = ['-fvisibility=default'] libsystemd_static = static_library( diff --git a/src/shared/enable-mempool.c b/src/shared/enable-mempool.c new file mode 100644 index 0000000000..a571b43f57 --- /dev/null +++ b/src/shared/enable-mempool.c @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + +#include "mempool.h" + +const bool mempool_use_allowed = true; diff --git a/src/shared/meson.build b/src/shared/meson.build index 498b73c750..84d52a37eb 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -36,6 +36,7 @@ shared_sources = files(''' dropin.h efivars.c efivars.h + enable-mempool.c fdset.c fdset.h firewall-util.h