From 38b59a83d2caee6cede2d6946c4cc11ee54efea8 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 25 Nov 2025 03:26:10 +0100 Subject: [PATCH] libmount-util: build .c only if libmount feature is enabled 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 | 11 +---------- src/shared/libmount-util.h | 13 ++++++++++--- src/shared/meson.build | 13 ++++++++----- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/shared/libmount-util.c b/src/shared/libmount-util.c index 8de8baeff80..c6c6074c259 100644 --- a/src/shared/libmount-util.c +++ b/src/shared/libmount-util.c @@ -1,11 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include "libmount-util.h" - -#if HAVE_LIBMOUNT #include #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 diff --git a/src/shared/libmount-util.h b/src/shared/libmount-util.h index 2f742996252..bfbb00cd4af 100644 --- a/src/shared/libmount-util.h +++ b/src/shared/libmount-util.h @@ -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); diff --git a/src/shared/meson.build b/src/shared/meson.build index f2d73118bbe..671bcb2f4f7 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -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], -- 2.47.3