core: Make libmount optional

Instead of skipping libcore entirely when libmount is not available,
let's only compile out the pieces that need libmount. This makes the
meson logic much less complex and allows systemd-analyze to be built
when libmount is not available.
This commit is contained in:
Daan De Meyer
2025-11-24 15:33:26 +01:00
parent 9c2cd09420
commit 5df44d0f6a
4 changed files with 47 additions and 31 deletions

View File

@@ -1,36 +1,5 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
load_fragment_gperf_gperf = custom_target(
input : 'load-fragment-gperf.gperf.in',
output: 'load-fragment-gperf.gperf',
command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'])
libcore_build_dir = meson.current_build_dir()
core_includes = [includes, include_directories('.')]
systemd_pc = custom_target(
input : 'systemd.pc.in',
output : 'systemd.pc',
command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'],
install : pkgconfigdatadir != 'no',
install_tag : 'devel',
install_dir : pkgconfigdatadir)
if conf.get('HAVE_LIBMOUNT') != 1
libcore = disabler()
core_test_template = test_template + {
'link_with' : [
libcore,
libshared,
],
'include_directories' : core_includes,
'suite' : 'core',
}
subdir_done()
endif
libcore_sources = files(
'audit-fd.c',
'automount.c',
@@ -115,6 +84,11 @@ endif
sources += libcore_sources
load_fragment_gperf_gperf = custom_target(
input : 'load-fragment-gperf.gperf.in',
output: 'load-fragment-gperf.gperf',
command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'])
load_fragment_gperf_c = custom_target(
input : load_fragment_gperf_gperf,
output : 'load-fragment-gperf.c',
@@ -149,6 +123,7 @@ man_page_depends += bpf_delegate_xml
generated_sources += [load_fragment_gperf_c, load_fragment_gperf_nulstr_c, bpf_delegate_configs_inc]
libcore_sources += [load_fragment_gperf_c, load_fragment_gperf_nulstr_c, bpf_delegate_configs_inc]
libcore_build_dir = meson.current_build_dir()
libcore_name = 'systemd-core-@0@'.format(shared_lib_tag)
libcore_static = static_library(
@@ -182,6 +157,8 @@ libcore = shared_library(
install : true,
install_dir : pkglibdir)
core_includes = [includes, include_directories('.')]
systemd_sources = files(
'main.c',
'crash-handler.c',
@@ -286,6 +263,14 @@ foreach item : in_files
install_dir : dir)
endforeach
systemd_pc = custom_target(
input : 'systemd.pc.in',
output : 'systemd.pc',
command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'],
install : pkgconfigdatadir != 'no',
install_tag : 'devel',
install_dir : pkgconfigdatadir)
install_data('org.freedesktop.systemd1.conf',
install_dir : dbuspolicydir)
install_data('org.freedesktop.systemd1.service',

View File

@@ -60,7 +60,9 @@ static const UnitActiveState state_translation_table[_MOUNT_STATE_MAX] = {
};
static int mount_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata);
#if HAVE_LIBMOUNT
static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata);
#endif
static void mount_enter_dead(Mount *m, MountResult f, bool flush_result);
static void mount_enter_mounted(Mount *m, MountResult f);
static void mount_cycle_clear(Mount *m);
@@ -1744,6 +1746,7 @@ static int mount_dispatch_timer(sd_event_source *source, usec_t usec, void *user
return 0;
}
#if HAVE_LIBMOUNT
static int mount_setup_new_unit(
Manager *m,
const char *name,
@@ -1924,8 +1927,10 @@ static int mount_setup_unit(
return 0;
}
#endif
static int mount_load_proc_self_mountinfo(Manager *m, bool set_flags) {
#if HAVE_LIBMOUNT
_cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL;
_cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL;
_cleanup_set_free_ Set *devices = NULL;
@@ -1965,6 +1970,9 @@ static int mount_load_proc_self_mountinfo(Manager *m, bool set_flags) {
}
return 0;
#else
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "libmount support not compiled in");
#endif
}
static void mount_shutdown(Manager *m) {
@@ -2042,6 +2050,7 @@ static bool mount_is_mounted(Mount *m) {
return UNIT(m)->perpetual || FLAGS_SET(m->proc_flags, MOUNT_PROC_IS_MOUNTED);
}
#if HAVE_LIBMOUNT
static int mount_on_ratelimit_expire(sd_event_source *s, void *userdata) {
Manager *m = ASSERT_PTR(userdata);
Job *j;
@@ -2060,8 +2069,10 @@ static int mount_on_ratelimit_expire(sd_event_source *s, void *userdata) {
return 0;
}
#endif
static void mount_enumerate(Manager *m) {
#if HAVE_LIBMOUNT
int r;
assert(m);
@@ -2154,9 +2165,14 @@ static void mount_enumerate(Manager *m) {
fail:
mount_shutdown(m);
#else
log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Cannot enumerate mounts, as libmount support is not compiled in");
mount_shutdown(m);
#endif
}
static int drain_libmount(Manager *m) {
#if HAVE_LIBMOUNT
bool rescan = false;
int r;
@@ -2180,6 +2196,9 @@ static int drain_libmount(Manager *m) {
} while (r == 0);
return rescan;
#else
return 0;
#endif
}
static int mount_process_proc_self_mountinfo(Manager *m) {
@@ -2294,6 +2313,7 @@ static int mount_process_proc_self_mountinfo(Manager *m) {
return 0;
}
#if HAVE_LIBMOUNT
static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
Manager *m = ASSERT_PTR(userdata);
@@ -2301,6 +2321,7 @@ static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
return mount_process_proc_self_mountinfo(m);
}
#endif
static void mount_reset_failed(Unit *u) {
Mount *m = MOUNT(u);

View File

@@ -70,6 +70,15 @@ int libmount_parse_fstab(struct libmnt_table **ret_table, struct libmnt_iter **r
int libmount_is_leaf(
struct libmnt_table *table,
struct libmnt_fs *fs);
#else
struct libmnt_monitor;
static inline void *sym_mnt_unref_monitor(struct libmnt_monitor *p) {
assert(p == NULL);
return NULL;
}
#endif
int dlopen_libmount(void);

View File

@@ -576,6 +576,7 @@ executables += [
'sources' : files('test-namespace.c'),
'dependencies' : [
threads,
libmount_cflags,
],
},
core_test_template + {