]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libmount-util: build .c only if libmount feature is enabled 39884/head
authorMike Yuan <me@yhndnzj.com>
Tue, 25 Nov 2025 02:26:10 +0000 (03:26 +0100)
committerMike Yuan <me@yhndnzj.com>
Wed, 26 Nov 2025 01:40:28 +0000 (02:40 +0100)
Follow-up for 7336f2c748fd37a60a3f5353ad198c1534d6cb5f

This alignes with some other optional modules in shraed/,
and it allows dlopen_libmount() to be optimized out entirely.
Let's avoid emitting pointless symbols.

src/shared/libmount-util.c
src/shared/libmount-util.h
src/shared/meson.build

index 8de8baeff801286f1c03b5d53356478798b44e58..c6c6074c2595335f4fe2b2691dbef63c47d3ab87 100644 (file)
@@ -1,11 +1,9 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#include "libmount-util.h"
-
-#if HAVE_LIBMOUNT
 #include <stdio.h>
 
 #include "fstab-util.h"
+#include "libmount-util.h"
 #include "log.h"
 
 static void *libmount_dl = NULL;
@@ -41,10 +39,8 @@ DLSYM_PROTOTYPE(mnt_table_parse_mtab) = NULL;
 DLSYM_PROTOTYPE(mnt_table_parse_stream) = NULL;
 DLSYM_PROTOTYPE(mnt_table_parse_swaps) = NULL;
 DLSYM_PROTOTYPE(mnt_unref_monitor) = NULL;
-#endif
 
 int dlopen_libmount(void) {
-#if HAVE_LIBMOUNT
         ELF_NOTE_DLOPEN("mount",
                         "Support for mount enumeration",
                         ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
@@ -85,12 +81,8 @@ int dlopen_libmount(void) {
                         DLSYM_ARG(mnt_table_parse_stream),
                         DLSYM_ARG(mnt_table_parse_swaps),
                         DLSYM_ARG(mnt_unref_monitor));
-#else
-        return -EOPNOTSUPP;
-#endif
 }
 
-#if HAVE_LIBMOUNT
 int libmount_parse_full(
                 const char *path,
                 FILE *source,
@@ -159,4 +151,3 @@ int libmount_is_leaf(
 
         return r == 1;
 }
-#endif
index 2f742996252f5ecce8ad60bfcc71026c964c6931..bfbb00cd4afd4726bb64b1c593f96327c29d8a4d 100644 (file)
@@ -42,6 +42,8 @@ extern DLSYM_PROTOTYPE(mnt_table_parse_stream);
 extern DLSYM_PROTOTYPE(mnt_table_parse_swaps);
 extern DLSYM_PROTOTYPE(mnt_unref_monitor);
 
+int dlopen_libmount(void);
+
 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct libmnt_table*, sym_mnt_free_table, mnt_free_tablep, NULL);
 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct libmnt_iter*, sym_mnt_free_iter, mnt_free_iterp, NULL);
 
@@ -56,12 +58,14 @@ static inline int libmount_parse_mountinfo(
                 FILE *source,
                 struct libmnt_table **ret_table,
                 struct libmnt_iter **ret_iter) {
+
         return libmount_parse_full("/proc/self/mountinfo", source, MNT_ITER_FORWARD, ret_table, ret_iter);
 }
 
 static inline int libmount_parse_with_utab(
                 struct libmnt_table **ret_table,
                 struct libmnt_iter **ret_iter) {
+
         return libmount_parse_full(NULL, NULL, MNT_ITER_FORWARD, ret_table, ret_iter);
 }
 
@@ -70,15 +74,18 @@ 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) {
+static inline int dlopen_libmount(void) {
+        return -EOPNOTSUPP;
+}
+
+static inline void* sym_mnt_unref_monitor(struct libmnt_monitor *p) {
         assert(p == NULL);
         return NULL;
 }
 
 #endif
-
-int dlopen_libmount(void);
index f2d73118bbe05ef695114f4732705b4398d90740..671bcb2f4f7783ea7c7efba831aafe5b08a27ee9 100644 (file)
@@ -115,7 +115,6 @@ shared_sources = files(
         'libaudit-util.c',
         'libcrypt-util.c',
         'libfido2-util.c',
-        'libmount-util.c',
         'local-addresses.c',
         'locale-setup.c',
         'log-assert-critical.c',
@@ -239,10 +238,6 @@ shared_sources = files(
         'xml.c',
 )
 
-if conf.get('ENABLE_NSS') == 1
-        shared_sources += files('nss-util.c')
-endif
-
 if get_option('tests') != 'false'
         shared_sources += files('tests.c')
 endif
@@ -257,6 +252,10 @@ syscall_list_inc = custom_target(
 generated_sources += syscall_list_inc
 shared_sources += syscall_list_inc
 
+if conf.get('ENABLE_NSS') == 1
+        shared_sources += files('nss-util.c')
+endif
+
 if conf.get('ENABLE_UTMP') == 1
         shared_sources += files('utmp-wtmp.c')
 endif
@@ -269,6 +268,10 @@ if conf.get('HAVE_PAM') == 1
         shared_sources += files('pam-util.c')
 endif
 
+if conf.get('HAVE_LIBMOUNT') == 1
+        shared_sources += files('libmount-util.c')
+endif
+
 generate_ip_protocol_list = files('generate-ip-protocol-list.sh')
 ip_protocol_list_txt = custom_target(
         input : [generate_ip_protocol_list, ipproto_sources],