dlopen: take log_level argument and log in fallback stubs
Every dlopen_xxx() helper now takes an int log_level argument. It is passed through to dlopen_many_sym_or_warn() (which in turn propagates it to dlopen_verbose() for the library-not-installed case), and is used by the fallback stub when support for the library is not compiled in to emit a "<lib> support is not compiled in." message at the caller's level. Callers pass LOG_DEBUG when gracefully degrading, or a higher level when the failure should surface, and no longer need to log redundantly at the call site. As part of this, dlopen_bpf_full() (which already took a log_level) is merged into dlopen_bpf() rather than keeping both. The static inline fallbacks used to live in the headers, which required pulling log.h in from every header that declared a dlopen_xxx(). Move them into the .c files instead: the declaration is always outside the #if HAVE_XXX block, the impl sits outside the outer #if HAVE_XXX wrap with its own internal #if HAVE_XXX/#else/#endif, and apparmor-util.c, idn-util.c, libmount-util.c and pam-util.c are now always compiled so they can host their stubs.
This commit is contained in:
committed by
Zbigniew Jędrzejewski-Szmek
parent
2d28d3cb91
commit
d49f3f287a
+57
-47
@@ -1,12 +1,15 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "libmount-util.h"
|
||||
#include "log.h"
|
||||
|
||||
#if HAVE_LIBMOUNT
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "sd-dlopen.h"
|
||||
|
||||
#include "fstab-util.h"
|
||||
#include "libmount-util.h"
|
||||
#include "log.h"
|
||||
|
||||
static void *libmount_dl = NULL;
|
||||
|
||||
@@ -42,50 +45,6 @@ DLSYM_PROTOTYPE(mnt_table_parse_stream) = NULL;
|
||||
DLSYM_PROTOTYPE(mnt_table_parse_swaps) = NULL;
|
||||
DLSYM_PROTOTYPE(mnt_unref_monitor) = NULL;
|
||||
|
||||
int dlopen_libmount(void) {
|
||||
SD_ELF_NOTE_DLOPEN(
|
||||
"mount",
|
||||
"Support for mount enumeration",
|
||||
SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
|
||||
"libmount.so.1");
|
||||
|
||||
return dlopen_many_sym_or_warn(
|
||||
&libmount_dl,
|
||||
"libmount.so.1",
|
||||
LOG_DEBUG,
|
||||
DLSYM_ARG(mnt_free_iter),
|
||||
DLSYM_ARG(mnt_free_table),
|
||||
DLSYM_ARG(mnt_fs_get_fs_options),
|
||||
DLSYM_ARG(mnt_fs_get_fstype),
|
||||
DLSYM_ARG(mnt_fs_get_id),
|
||||
DLSYM_ARG(mnt_fs_get_option),
|
||||
DLSYM_ARG(mnt_fs_get_options),
|
||||
DLSYM_ARG(mnt_fs_get_passno),
|
||||
DLSYM_ARG(mnt_fs_get_propagation),
|
||||
DLSYM_ARG(mnt_fs_get_source),
|
||||
DLSYM_ARG(mnt_fs_get_target),
|
||||
DLSYM_ARG(mnt_fs_get_vfs_options),
|
||||
DLSYM_ARG(mnt_get_builtin_optmap),
|
||||
DLSYM_ARG(mnt_init_debug),
|
||||
DLSYM_ARG(mnt_monitor_enable_kernel),
|
||||
DLSYM_ARG(mnt_monitor_enable_userspace),
|
||||
DLSYM_ARG(mnt_monitor_get_fd),
|
||||
DLSYM_ARG(mnt_monitor_next_change),
|
||||
DLSYM_ARG(mnt_new_iter),
|
||||
DLSYM_ARG(mnt_new_monitor),
|
||||
DLSYM_ARG(mnt_new_table),
|
||||
DLSYM_ARG(mnt_optstr_get_flags),
|
||||
DLSYM_ARG(mnt_table_find_devno),
|
||||
DLSYM_ARG(mnt_table_find_target),
|
||||
DLSYM_ARG(mnt_table_next_child_fs),
|
||||
DLSYM_ARG(mnt_table_next_fs),
|
||||
DLSYM_ARG(mnt_table_parse_file),
|
||||
DLSYM_ARG(mnt_table_parse_mtab),
|
||||
DLSYM_ARG(mnt_table_parse_stream),
|
||||
DLSYM_ARG(mnt_table_parse_swaps),
|
||||
DLSYM_ARG(mnt_unref_monitor));
|
||||
}
|
||||
|
||||
int libmount_parse_full(
|
||||
const char *path,
|
||||
FILE *source,
|
||||
@@ -103,7 +62,7 @@ int libmount_parse_full(
|
||||
assert(ret_table);
|
||||
assert(ret_iter);
|
||||
|
||||
r = dlopen_libmount();
|
||||
r = dlopen_libmount(LOG_DEBUG);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -156,3 +115,54 @@ int libmount_is_leaf(
|
||||
|
||||
return r == 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int dlopen_libmount(int log_level) {
|
||||
#if HAVE_LIBMOUNT
|
||||
SD_ELF_NOTE_DLOPEN(
|
||||
"mount",
|
||||
"Support for mount enumeration",
|
||||
SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
|
||||
"libmount.so.1");
|
||||
|
||||
return dlopen_many_sym_or_warn(
|
||||
&libmount_dl,
|
||||
"libmount.so.1",
|
||||
log_level,
|
||||
DLSYM_ARG(mnt_free_iter),
|
||||
DLSYM_ARG(mnt_free_table),
|
||||
DLSYM_ARG(mnt_fs_get_fs_options),
|
||||
DLSYM_ARG(mnt_fs_get_fstype),
|
||||
DLSYM_ARG(mnt_fs_get_id),
|
||||
DLSYM_ARG(mnt_fs_get_option),
|
||||
DLSYM_ARG(mnt_fs_get_options),
|
||||
DLSYM_ARG(mnt_fs_get_passno),
|
||||
DLSYM_ARG(mnt_fs_get_propagation),
|
||||
DLSYM_ARG(mnt_fs_get_source),
|
||||
DLSYM_ARG(mnt_fs_get_target),
|
||||
DLSYM_ARG(mnt_fs_get_vfs_options),
|
||||
DLSYM_ARG(mnt_get_builtin_optmap),
|
||||
DLSYM_ARG(mnt_init_debug),
|
||||
DLSYM_ARG(mnt_monitor_enable_kernel),
|
||||
DLSYM_ARG(mnt_monitor_enable_userspace),
|
||||
DLSYM_ARG(mnt_monitor_get_fd),
|
||||
DLSYM_ARG(mnt_monitor_next_change),
|
||||
DLSYM_ARG(mnt_new_iter),
|
||||
DLSYM_ARG(mnt_new_monitor),
|
||||
DLSYM_ARG(mnt_new_table),
|
||||
DLSYM_ARG(mnt_optstr_get_flags),
|
||||
DLSYM_ARG(mnt_table_find_devno),
|
||||
DLSYM_ARG(mnt_table_find_target),
|
||||
DLSYM_ARG(mnt_table_next_child_fs),
|
||||
DLSYM_ARG(mnt_table_next_fs),
|
||||
DLSYM_ARG(mnt_table_parse_file),
|
||||
DLSYM_ARG(mnt_table_parse_mtab),
|
||||
DLSYM_ARG(mnt_table_parse_stream),
|
||||
DLSYM_ARG(mnt_table_parse_swaps),
|
||||
DLSYM_ARG(mnt_unref_monitor));
|
||||
#else
|
||||
return log_full_errno(log_level, SYNTHETIC_ERRNO(EOPNOTSUPP),
|
||||
"libmount support is not compiled in.");
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user