libmount-util: build .c only if libmount feature is enabled

Follow-up for 7336f2c748

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.
This commit is contained in:
Mike Yuan
2025-11-25 03:26:10 +01:00
parent 46b4b33c25
commit 38b59a83d2
3 changed files with 19 additions and 18 deletions

View 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

View 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);

View 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],