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:
Daan De Meyer
2026-04-22 17:41:42 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent 2d28d3cb91
commit d49f3f287a
112 changed files with 796 additions and 755 deletions
+8 -7
View File
@@ -98,7 +98,7 @@ void cryptsetup_enable_logging(struct crypt_device *cd) {
* endless loop, but isn't because we break it via the check for 'cryptsetup_dl' early in
* dlopen_cryptsetup(). */
if (dlopen_cryptsetup() < 0)
if (dlopen_cryptsetup(LOG_DEBUG) < 0)
return; /* If this fails, let's gracefully ignore the issue, this is just debug logging after
* all, and if this failed we already generated a debug log message that should help
* to track things down. */
@@ -124,7 +124,7 @@ int cryptsetup_set_minimal_pbkdf(struct crypt_device *cd) {
/* Sets a minimal PKBDF in case we already have a high entropy key. */
r = dlopen_cryptsetup();
r = dlopen_cryptsetup(LOG_DEBUG);
if (r < 0)
return r;
@@ -155,7 +155,7 @@ int cryptsetup_get_token_as_json(
* -EMEDIUMTYPE → "verify_type" specified and doesn't match token's type
*/
r = dlopen_cryptsetup();
r = dlopen_cryptsetup(LOG_DEBUG);
if (r < 0)
return r;
@@ -188,7 +188,7 @@ int cryptsetup_add_token_json(struct crypt_device *cd, sd_json_variant *v) {
_cleanup_free_ char *text = NULL;
int r;
r = dlopen_cryptsetup();
r = dlopen_cryptsetup(LOG_DEBUG);
if (r < 0)
return r;
@@ -268,7 +268,7 @@ int cryptsetup_get_volume_key_id(
}
#endif
int dlopen_cryptsetup(void) {
int dlopen_cryptsetup(int log_level) {
#if HAVE_LIBCRYPTSETUP
int r;
@@ -284,7 +284,7 @@ int dlopen_cryptsetup(void) {
"libcryptsetup.so.12");
r = dlopen_many_sym_or_warn(
&cryptsetup_dl, "libcryptsetup.so.12", LOG_DEBUG,
&cryptsetup_dl, "libcryptsetup.so.12", log_level,
DLSYM_ARG(crypt_activate_by_passphrase),
DLSYM_ARG(crypt_activate_by_signed_key),
DLSYM_ARG(crypt_activate_by_volume_key),
@@ -355,7 +355,8 @@ int dlopen_cryptsetup(void) {
return 1;
#else
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "cryptsetup support is not compiled in.");
return log_full_errno(log_level, SYNTHETIC_ERRNO(EOPNOTSUPP),
"libcryptsetup support is not compiled in.");
#endif
}