]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: Make libmount optional 39878/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 24 Nov 2025 14:33:26 +0000 (15:33 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 24 Nov 2025 15:23:10 +0000 (16:23 +0100)
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.

src/core/meson.build
src/core/mount.c
src/shared/libmount-util.h
src/test/meson.build

index 8d4355dad8e74766ac1f87701513e5b1cfb18361..c7beb8742ad8432aabd2a7013def15409ea2869e 100644 (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',
index 5ab36f4733677f87a30739a7fad79ac1a7c5cd1e..3bd22bfb9ca21e44b8fbad1edb81c243b8519704 100644 (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);
index 1438efbfd1afd9c8e26c30864e789406bfb6b86c..2f742996252f5ecce8ad60bfcc71026c964c6931 100644 (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);
index 6a66c51aea545b10d73a46d8023b1b30cb2e44e1..2974700954876e4e3301c51cb81f9689b24cd4c6 100644 (file)
@@ -576,6 +576,7 @@ executables += [
                 'sources' : files('test-namespace.c'),
                 'dependencies' : [
                         threads,
+                        libmount_cflags,
                 ],
         },
         core_test_template + {