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
@@ -31,7 +31,7 @@ int bpf_bind_network_interface_supported(void) {
|
||||
if (supported >= 0)
|
||||
return supported;
|
||||
|
||||
if (dlopen_bpf_full(LOG_WARNING) < 0)
|
||||
if (dlopen_bpf(LOG_WARNING) < 0)
|
||||
return (supported = false);
|
||||
|
||||
obj = bind_iface_bpf__open();
|
||||
|
||||
@@ -91,7 +91,7 @@ bool bpf_restrict_fs_supported(bool initialize) {
|
||||
if (!initialize)
|
||||
return false;
|
||||
|
||||
if (dlopen_bpf_full(LOG_WARNING) < 0)
|
||||
if (dlopen_bpf(LOG_WARNING) < 0)
|
||||
return (supported = false);
|
||||
|
||||
r = lsm_supported("bpf");
|
||||
|
||||
@@ -86,7 +86,7 @@ int bpf_restrict_ifaces_supported(void) {
|
||||
if (supported >= 0)
|
||||
return supported;
|
||||
|
||||
if (dlopen_bpf_full(LOG_WARNING) < 0)
|
||||
if (dlopen_bpf(LOG_WARNING) < 0)
|
||||
return (supported = false);
|
||||
|
||||
r = prepare_restrict_ifaces_bpf(NULL, true, NULL, &obj);
|
||||
|
||||
@@ -125,7 +125,7 @@ int bpf_socket_bind_supported(void) {
|
||||
_cleanup_(socket_bind_bpf_freep) struct socket_bind_bpf *obj = NULL;
|
||||
int r;
|
||||
|
||||
if (dlopen_bpf_full(LOG_WARNING) < 0)
|
||||
if (dlopen_bpf(LOG_WARNING) < 0)
|
||||
return false;
|
||||
|
||||
r = prepare_socket_bind_bpf(/* unit= */ NULL, /* allow_rules= */ NULL, /* deny_rules= */ NULL, &obj);
|
||||
|
||||
@@ -1359,9 +1359,9 @@ static int setup_pam(
|
||||
* parent process will exec() the actual daemon. We do things this way to ensure that the main PID of
|
||||
* the daemon is the one we initially fork()ed. */
|
||||
|
||||
r = dlopen_libpam();
|
||||
r = dlopen_libpam(LOG_ERR);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "PAM support not available: %m");
|
||||
return r;
|
||||
|
||||
r = barrier_create(&barrier);
|
||||
if (r < 0)
|
||||
@@ -1625,7 +1625,7 @@ static bool seccomp_allows_drop_privileges(const ExecContext *c) {
|
||||
assert(c);
|
||||
|
||||
/* No libseccomp, all is fine */
|
||||
if (dlopen_libseccomp() < 0)
|
||||
if (dlopen_libseccomp(LOG_DEBUG) < 0)
|
||||
return true;
|
||||
|
||||
/* No syscall filter, we are allowed to drop privileges */
|
||||
@@ -1927,7 +1927,7 @@ static int apply_restrict_filesystems(const ExecContext *c, const ExecParameters
|
||||
}
|
||||
|
||||
/* We are in a new binary, so dl-open again */
|
||||
r = dlopen_bpf();
|
||||
r = dlopen_bpf(LOG_DEBUG);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -6026,10 +6026,10 @@ int exec_invoke(
|
||||
}
|
||||
|
||||
/* Load a bunch of libraries we'll possibly need later, before we turn off dlopen() */
|
||||
(void) dlopen_bpf();
|
||||
(void) dlopen_cryptsetup();
|
||||
(void) dlopen_libmount();
|
||||
(void) dlopen_libseccomp();
|
||||
(void) dlopen_bpf(LOG_DEBUG);
|
||||
(void) dlopen_cryptsetup(LOG_DEBUG);
|
||||
(void) dlopen_libmount(LOG_DEBUG);
|
||||
(void) dlopen_libseccomp(LOG_DEBUG);
|
||||
|
||||
/* Let's now disable further dlopen()ing of libraries, since we are about to do namespace
|
||||
* shenanigans, and do not want to mix resources from host and namespace */
|
||||
|
||||
+3
-3
@@ -1491,7 +1491,7 @@ void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix) {
|
||||
fputc('~', f);
|
||||
|
||||
#if HAVE_SECCOMP
|
||||
if (dlopen_libseccomp() >= 0) {
|
||||
if (dlopen_libseccomp(LOG_DEBUG) >= 0) {
|
||||
void *id, *val;
|
||||
bool first = true;
|
||||
HASHMAP_FOREACH_KEY(val, id, c->syscall_filter) {
|
||||
@@ -1910,7 +1910,7 @@ char** exec_context_get_syscall_filter(const ExecContext *c) {
|
||||
assert(c);
|
||||
|
||||
#if HAVE_SECCOMP
|
||||
if (dlopen_libseccomp() < 0)
|
||||
if (dlopen_libseccomp(LOG_DEBUG) < 0)
|
||||
return strv_new(NULL);
|
||||
|
||||
void *id, *val;
|
||||
@@ -1979,7 +1979,7 @@ char** exec_context_get_syscall_log(const ExecContext *c) {
|
||||
assert(c);
|
||||
|
||||
#if HAVE_SECCOMP
|
||||
if (dlopen_libseccomp() < 0)
|
||||
if (dlopen_libseccomp(LOG_DEBUG) < 0)
|
||||
return strv_new(NULL);
|
||||
|
||||
void *id, *val;
|
||||
|
||||
+1
-1
@@ -3378,7 +3378,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
/* Building without libmount is allowed, but if it is compiled in, then we must be able to load it */
|
||||
r = dlopen_libmount();
|
||||
r = dlopen_libmount(LOG_DEBUG);
|
||||
if (r < 0 && !ERRNO_IS_NEG_NOT_SUPPORTED(r)) {
|
||||
error_message = "Failed to load libmount.so";
|
||||
goto finish;
|
||||
|
||||
+1
-1
@@ -2408,7 +2408,7 @@ static int mount_test_startable(Unit *u) {
|
||||
}
|
||||
|
||||
static bool mount_supported(void) {
|
||||
return dlopen_libmount() >= 0;
|
||||
return dlopen_libmount(LOG_DEBUG) >= 0;
|
||||
}
|
||||
|
||||
static int mount_subsystem_ratelimited(Manager *m) {
|
||||
|
||||
@@ -3984,7 +3984,7 @@ int refresh_extensions_in_namespace(
|
||||
if (r > 0)
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Target namespace is not separate, cannot reload extensions");
|
||||
|
||||
(void) dlopen_cryptsetup();
|
||||
(void) dlopen_cryptsetup(LOG_DEBUG);
|
||||
|
||||
extension_dir = path_join(p->private_namespace_dir, "unit-extensions");
|
||||
if (!extension_dir)
|
||||
|
||||
@@ -17,11 +17,9 @@ int mac_selinux_setup(bool *loaded_policy) {
|
||||
|
||||
assert(loaded_policy);
|
||||
|
||||
r = dlopen_libselinux();
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "No SELinux library available, skipping setup.");
|
||||
r = dlopen_libselinux(LOG_DEBUG);
|
||||
if (r < 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
mac_selinux_disable_logging();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user