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
+34 -24
View File
@@ -1,13 +1,16 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "apparmor-util.h"
#include "log.h"
#if HAVE_APPARMOR
#include <syslog.h>
#include "sd-dlopen.h"
#include "alloc-util.h"
#include "apparmor-util.h"
#include "fileio.h"
#include "log.h"
#include "parse-util.h"
static void *libapparmor_dl = NULL;
@@ -21,27 +24,6 @@ DLSYM_PROTOTYPE(aa_policy_cache_new) = NULL;
DLSYM_PROTOTYPE(aa_policy_cache_replace_all) = NULL;
DLSYM_PROTOTYPE(aa_policy_cache_unref) = NULL;
int dlopen_libapparmor(void) {
SD_ELF_NOTE_DLOPEN(
"apparmor",
"Support for AppArmor policies",
SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
"libapparmor.so.1");
return dlopen_many_sym_or_warn(
&libapparmor_dl,
"libapparmor.so.1",
LOG_DEBUG,
DLSYM_ARG(aa_change_onexec),
DLSYM_ARG(aa_change_profile),
DLSYM_ARG(aa_features_new_from_kernel),
DLSYM_ARG(aa_features_unref),
DLSYM_ARG(aa_policy_cache_dir_path_preview),
DLSYM_ARG(aa_policy_cache_new),
DLSYM_ARG(aa_policy_cache_replace_all),
DLSYM_ARG(aa_policy_cache_unref));
}
bool mac_apparmor_use(void) {
static int cached_use = -1;
int r;
@@ -63,8 +45,36 @@ bool mac_apparmor_use(void) {
if (r <= 0)
return (cached_use = false);
if (dlopen_libapparmor() < 0)
if (dlopen_libapparmor(LOG_DEBUG) < 0)
return (cached_use = false);
return (cached_use = true);
}
#endif
int dlopen_libapparmor(int log_level) {
#if HAVE_APPARMOR
SD_ELF_NOTE_DLOPEN(
"apparmor",
"Support for AppArmor policies",
SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
"libapparmor.so.1");
return dlopen_many_sym_or_warn(
&libapparmor_dl,
"libapparmor.so.1",
log_level,
DLSYM_ARG(aa_change_onexec),
DLSYM_ARG(aa_change_profile),
DLSYM_ARG(aa_features_new_from_kernel),
DLSYM_ARG(aa_features_unref),
DLSYM_ARG(aa_policy_cache_dir_path_preview),
DLSYM_ARG(aa_policy_cache_new),
DLSYM_ARG(aa_policy_cache_replace_all),
DLSYM_ARG(aa_policy_cache_unref));
#else
return log_full_errno(log_level, SYNTHETIC_ERRNO(EOPNOTSUPP),
"libapparmor support is not compiled in.");
#endif
}