1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-23 17:34:00 +03:00

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
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-10-09 16:02:55 +02:00
parent 7c48ea0280
commit a5d8835c78
7 changed files with 20 additions and 0 deletions

View File

@ -1380,6 +1380,7 @@ libjournal_core = static_library(
libsystemd_sym_path = '@0@/@1@'.format(meson.current_source_dir(), libsystemd_sym) libsystemd_sym_path = '@0@/@1@'.format(meson.current_source_dir(), libsystemd_sym)
libsystemd = shared_library( libsystemd = shared_library(
'systemd', 'systemd',
disable_mempool_c,
version : libsystemd_version, version : libsystemd_version,
include_directories : includes, include_directories : includes,
link_args : ['-shared', link_args : ['-shared',
@ -1461,6 +1462,7 @@ subdir('test')
test_dlopen = executable( test_dlopen = executable(
'test-dlopen', 'test-dlopen',
test_dlopen_c, test_dlopen_c,
disable_mempool_c,
include_directories : includes, include_directories : includes,
link_with : [libbasic], link_with : [libbasic],
dependencies : [libdl], dependencies : [libdl],
@ -1481,6 +1483,7 @@ foreach tuple : [['myhostname', 'ENABLE_NSS_MYHOSTNAME'],
nss = shared_library( nss = shared_library(
'nss_' + module, 'nss_' + module,
'src/nss-@0@/nss-@0@.c'.format(module), 'src/nss-@0@/nss-@0@.c'.format(module),
disable_mempool_c,
version : '2', version : '2',
include_directories : includes, include_directories : includes,
# Note that we link NSS modules with '-z nodelete' so that mempools never get orphaned # Note that we link NSS modules with '-z nodelete' so that mempools never get orphaned

View File

@ -78,6 +78,8 @@ bool mempool_enabled(void) {
if (!is_main_thread()) if (!is_main_thread())
return false; return false;
if (!mempool_use_allowed)
b = false;
if (b < 0) if (b < 0)
b = getenv_bool("SYSTEMD_MEMPOOL") != 0; b = getenv_bool("SYSTEMD_MEMPOOL") != 0;

View File

@ -1,6 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1+ */ /* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once #pragma once
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
struct pool; struct pool;
@ -22,6 +23,7 @@ static struct mempool pool_name = { \
.at_least = alloc_at_least, \ .at_least = alloc_at_least, \
} }
extern const bool mempool_use_allowed;
bool mempool_enabled(void); bool mempool_enabled(void);
#if VALGRIND #if VALGRIND

View File

@ -0,0 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "mempool.h"
const bool mempool_use_allowed = false;

View File

@ -81,6 +81,8 @@ libsystemd_sources = files('''
sd-utf8/sd-utf8.c sd-utf8/sd-utf8.c
'''.split()) + id128_sources + sd_daemon_c + sd_event_c + sd_login_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_c_args = ['-fvisibility=default']
libsystemd_static = static_library( libsystemd_static = static_library(

View File

@ -0,0 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "mempool.h"
const bool mempool_use_allowed = true;

View File

@ -36,6 +36,7 @@ shared_sources = files('''
dropin.h dropin.h
efivars.c efivars.c
efivars.h efivars.h
enable-mempool.c
fdset.c fdset.c
fdset.h fdset.h
firewall-util.h firewall-util.h