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
@@ -29,12 +29,12 @@
|
||||
#include "tests.h"
|
||||
#include "tpm2-util.h"
|
||||
|
||||
#define ASSERT_DLOPEN(func, cond) \
|
||||
do { \
|
||||
if (cond) \
|
||||
ASSERT_OK(func()); \
|
||||
else \
|
||||
ASSERT_ERROR(func(), EOPNOTSUPP); \
|
||||
#define ASSERT_DLOPEN(func, cond) \
|
||||
do { \
|
||||
if (cond) \
|
||||
ASSERT_OK(func(LOG_DEBUG)); \
|
||||
else \
|
||||
ASSERT_ERROR(func(LOG_DEBUG), EOPNOTSUPP); \
|
||||
} while (false)
|
||||
|
||||
static int run(int argc, char **argv) {
|
||||
|
||||
@@ -1633,7 +1633,7 @@ static int intro(void) {
|
||||
if (path_is_read_only_fs("/sys") > 0)
|
||||
return log_tests_skipped("/sys is mounted read-only");
|
||||
|
||||
r = dlopen_libmount();
|
||||
r = dlopen_libmount(LOG_DEBUG);
|
||||
if (r < 0)
|
||||
return log_tests_skipped("libmount not available.");
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ TEST(gzip_round_trip) {
|
||||
gz_path[] = "/tmp/test-kexec-gz.XXXXXX";
|
||||
int r;
|
||||
|
||||
r = dlopen_zlib();
|
||||
r = dlopen_zlib(LOG_DEBUG);
|
||||
if (r < 0) {
|
||||
log_tests_skipped("zlib not available");
|
||||
return;
|
||||
@@ -144,7 +144,7 @@ TEST(zboot_synthetic) {
|
||||
zboot_path[] = "/tmp/test-kexec-zboot.XXXXXX";
|
||||
int r;
|
||||
|
||||
r = dlopen_zlib();
|
||||
r = dlopen_zlib(LOG_DEBUG);
|
||||
if (r < 0) {
|
||||
log_tests_skipped("zlib not available");
|
||||
return;
|
||||
|
||||
@@ -972,7 +972,7 @@ TEST(config_parse_log_filter_patterns) {
|
||||
TEST_PATTERN("~foobar", 0, 1),
|
||||
};
|
||||
|
||||
if (ERRNO_IS_NOT_SUPPORTED(dlopen_pcre2()))
|
||||
if (ERRNO_IS_NOT_SUPPORTED(dlopen_pcre2(LOG_DEBUG)))
|
||||
return (void) log_tests_skipped("PCRE2 support is not available");
|
||||
|
||||
FOREACH_ELEMENT(test, regex_tests) {
|
||||
|
||||
@@ -213,7 +213,7 @@ TEST(protect_kernel_logs) {
|
||||
return;
|
||||
}
|
||||
|
||||
r = dlopen_libmount();
|
||||
r = dlopen_libmount(LOG_DEBUG);
|
||||
if (ERRNO_IS_NEG_NOT_SUPPORTED(r)) {
|
||||
(void) log_tests_skipped("libmount support not compiled in");
|
||||
return;
|
||||
|
||||
@@ -15,9 +15,9 @@ static int load_module(const char *mod_name) {
|
||||
struct kmod_list *l;
|
||||
int r;
|
||||
|
||||
r = dlopen_libkmod();
|
||||
r = dlopen_libkmod(LOG_ERR);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to load libkmod: %m");
|
||||
return r;
|
||||
|
||||
ctx = sym_kmod_new(NULL, NULL);
|
||||
if (!ctx)
|
||||
|
||||
Reference in New Issue
Block a user