tree-wide: convert dlopen_*() callers to DLOPEN_* wrapper macros

Switch the executable-owned call sites from the plain dlopen_<lib>()
helpers to the new DLOPEN_<LIB>() macros, so that each binary that loads
an optional library at runtime now carries its own .note.dlopen note
instead of relying solely on libsystemd-shared. Each call site passes a
priority reflecting whether it hard-depends on the library (required) or
degrades gracefully without it (recommended).

Co-developed-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Luca Boccassi
2026-06-01 18:46:24 +01:00
parent 590e226437
commit b0ede9f9ee
63 changed files with 127 additions and 127 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ int bpf_bind_network_interface_supported(void) {
if (supported >= 0)
return supported;
if (dlopen_bpf(LOG_WARNING) < 0)
if (DLOPEN_BPF(LOG_WARNING, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED) < 0)
return (supported = false);
obj = bind_iface_bpf__open();
+1 -1
View File
@@ -78,7 +78,7 @@ bool bpf_restrict_fs_supported(bool initialize) {
if (!initialize)
return false;
if (dlopen_bpf(LOG_WARNING) < 0)
if (DLOPEN_BPF(LOG_WARNING, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED) < 0)
return (supported = false);
r = lsm_supported("bpf");
+2 -2
View File
@@ -168,7 +168,7 @@ bool bpf_restrict_fsaccess_supported(void) {
if (supported >= 0)
return supported;
if (dlopen_bpf(LOG_WARNING) < 0)
if (DLOPEN_BPF(LOG_WARNING, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED) < 0)
return (supported = false);
r = lsm_supported("bpf");
@@ -338,7 +338,7 @@ static int restrict_fsaccess_validate_deserialized_fds(Manager *m) {
assert(m);
r = dlopen_bpf(LOG_WARNING);
r = DLOPEN_BPF(LOG_WARNING, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
if (r < 0)
return log_error_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE),
"bpf-restrict-fsaccess: Failed to load libbpf for FD validation, aborting.");
+1 -1
View File
@@ -86,7 +86,7 @@ int bpf_restrict_ifaces_supported(void) {
if (supported >= 0)
return supported;
if (dlopen_bpf(LOG_WARNING) < 0)
if (DLOPEN_BPF(LOG_WARNING, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED) < 0)
return (supported = false);
r = prepare_restrict_ifaces_bpf(NULL, true, NULL, &obj);
+1 -1
View File
@@ -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(LOG_WARNING) < 0)
if (DLOPEN_BPF(LOG_WARNING, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED) < 0)
return false;
r = prepare_socket_bind_bpf(/* unit= */ NULL, /* allow_rules= */ NULL, /* deny_rules= */ NULL, &obj);
+7 -7
View File
@@ -1313,7 +1313,7 @@ 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(LOG_ERR);
r = DLOPEN_LIBPAM(LOG_ERR, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
if (r < 0)
return r;
@@ -1579,7 +1579,7 @@ static bool seccomp_allows_drop_privileges(const ExecContext *c) {
assert(c);
/* No libseccomp, all is fine */
if (dlopen_libseccomp(LOG_DEBUG) < 0)
if (DLOPEN_LIBSECCOMP(LOG_DEBUG, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED) < 0)
return true;
/* No syscall filter, we are allowed to drop privileges */
@@ -1889,7 +1889,7 @@ static int apply_restrict_filesystems(const ExecContext *c, const ExecParameters
}
/* We are in a new binary, so dl-open again */
r = dlopen_bpf(LOG_DEBUG);
r = DLOPEN_BPF(LOG_DEBUG, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
if (r < 0)
return r;
@@ -5998,10 +5998,10 @@ int exec_invoke(
}
/* Load a bunch of libraries we'll possibly need later, before we turn off dlopen() */
(void) dlopen_bpf(LOG_DEBUG);
(void) dlopen_cryptsetup(LOG_DEBUG);
(void) dlopen_libmount(LOG_DEBUG);
(void) dlopen_libseccomp(LOG_DEBUG);
(void) DLOPEN_BPF(LOG_DEBUG, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
(void) DLOPEN_CRYPTSETUP(LOG_DEBUG, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
(void) DLOPEN_LIBMOUNT(LOG_DEBUG, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
(void) DLOPEN_LIBSECCOMP(LOG_DEBUG, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
/* 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
View File
@@ -1576,7 +1576,7 @@ void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix) {
fputc('~', f);
#if HAVE_SECCOMP
if (dlopen_libseccomp(LOG_DEBUG) >= 0) {
if (DLOPEN_LIBSECCOMP(LOG_DEBUG, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED) >= 0) {
void *id, *val;
bool first = true;
HASHMAP_FOREACH_KEY(val, id, c->syscall_filter) {
@@ -1995,7 +1995,7 @@ char** exec_context_get_syscall_filter(const ExecContext *c) {
assert(c);
#if HAVE_SECCOMP
if (dlopen_libseccomp(LOG_DEBUG) < 0)
if (DLOPEN_LIBSECCOMP(LOG_DEBUG, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED) < 0)
return strv_new(NULL);
void *id, *val;
@@ -2064,7 +2064,7 @@ char** exec_context_get_syscall_log(const ExecContext *c) {
assert(c);
#if HAVE_SECCOMP
if (dlopen_libseccomp(LOG_DEBUG) < 0)
if (DLOPEN_LIBSECCOMP(LOG_DEBUG, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED) < 0)
return strv_new(NULL);
void *id, *val;
+1 -1
View File
@@ -3690,7 +3690,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(LOG_DEBUG);
r = DLOPEN_LIBMOUNT(LOG_DEBUG, SD_ELF_NOTE_DLOPEN_PRIORITY_REQUIRED);
if (r < 0 && !ERRNO_IS_NEG_NOT_SUPPORTED(r)) {
error_message = "Failed to load libmount.so";
goto finish;
+1 -1
View File
@@ -2408,7 +2408,7 @@ static int mount_test_startable(Unit *u) {
}
static bool mount_supported(void) {
return dlopen_libmount(LOG_DEBUG) >= 0;
return DLOPEN_LIBMOUNT(LOG_DEBUG, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED) >= 0;
}
static int mount_subsystem_ratelimited(Manager *m) {
+1 -1
View File
@@ -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(LOG_DEBUG);
(void) DLOPEN_CRYPTSETUP(LOG_DEBUG, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
extension_dir = path_join(p->private_namespace_dir, "unit-extensions");
if (!extension_dir)
+1 -1
View File
@@ -17,7 +17,7 @@ int mac_selinux_setup(bool *loaded_policy) {
assert(loaded_policy);
r = dlopen_libselinux(LOG_DEBUG);
r = DLOPEN_LIBSELINUX(LOG_DEBUG, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
if (r < 0)
return 0;