summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-06-22 09:24:02 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-06-24 10:16:46 +0200
commit1622ef77ee4466074e7d785feabf6bc9115297c8 (patch)
tree3e6c23b55ed2e87850d8d0c9886ede87752871f8 /src
parentfff25ab22eec825a15c2647a84247221abd6b0c8 (diff)
downloadsystemd-1622ef77ee4466074e7d785feabf6bc9115297c8.tar.gz
various: convert to the new dlopen_or_warn() helper
Diffstat (limited to 'src')
-rw-r--r--src/journal/pcre2-dlopen.c29
-rw-r--r--src/shared/bpf-dlopen.c28
-rw-r--r--src/shared/cryptsetup-util.c23
-rw-r--r--src/shared/idn-util.c27
-rw-r--r--src/shared/libfido2-util.c26
-rw-r--r--src/shared/pwquality-util.c26
-rw-r--r--src/shared/qrcode-util.c28
7 files changed, 25 insertions, 162 deletions
diff --git a/src/journal/pcre2-dlopen.c b/src/journal/pcre2-dlopen.c
index 210e39a0ae..475d7eb26d 100644
--- a/src/journal/pcre2-dlopen.c
+++ b/src/journal/pcre2-dlopen.c
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#include "alloc-util.h"
#include "dlfcn-util.h"
+#include "log.h"
#include "pcre2-dlopen.h"
#if HAVE_PCRE2
@@ -16,17 +16,6 @@ int (*sym_pcre2_match)(const pcre2_code *, PCRE2_SPTR, PCRE2_SIZE, PCRE2_SIZE, u
PCRE2_SIZE* (*sym_pcre2_get_ovector_pointer)(pcre2_match_data *);
int dlopen_pcre2(void) {
- _cleanup_(dlclosep) void *dl = NULL;
- int r;
-
- if (pcre2_dl)
- return 0; /* Already loaded */
-
- dl = dlopen("libpcre2-8.so.0", RTLD_LAZY);
- if (!dl)
- return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "PCRE2 support is not installed: %s", dlerror());
-
/* So here's something weird: PCRE2 actually renames the symbols exported by the library via C
* macros, so that the exported symbols carry a suffix "_8" but when used from C the suffix is
* gone. In the argument list below we ignore this mangling. Surprisingly (at least to me), we
@@ -35,25 +24,15 @@ int dlopen_pcre2(void) {
* string actually contains the "_8" suffix already due to that and we don't have to append it
* manually anymore. C is weird. 🤯 */
- r = dlsym_many_or_warn(
- dl,
- LOG_ERR,
+ return dlopen_many_sym_or_warn(
+ &pcre2_dl, "libpcre2-8.so.0", LOG_ERR,
DLSYM_ARG(pcre2_match_data_create),
DLSYM_ARG(pcre2_match_data_free),
DLSYM_ARG(pcre2_code_free),
DLSYM_ARG(pcre2_compile),
DLSYM_ARG(pcre2_get_error_message),
DLSYM_ARG(pcre2_match),
- DLSYM_ARG(pcre2_get_ovector_pointer),
- NULL);
- if (r < 0)
- return r;
-
- /* Note that we never release the reference here, because there's no real reason to, after all this
- * was traditionally a regular shared library dependency which lives forever too. */
- pcre2_dl = TAKE_PTR(dl);
-
- return 1;
+ DLSYM_ARG(pcre2_get_ovector_pointer));
}
#else
diff --git a/src/shared/bpf-dlopen.c b/src/shared/bpf-dlopen.c
index 0d222ae19e..45ab986ab2 100644
--- a/src/shared/bpf-dlopen.c
+++ b/src/shared/bpf-dlopen.c
@@ -1,8 +1,8 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#include "alloc-util.h"
#include "dlfcn-util.h"
#include "bpf-dlopen.h"
+#include "log.h"
#if HAVE_LIBBPF
static void *bpf_dl = NULL;
@@ -24,20 +24,8 @@ bool (*sym_bpf_probe_prog_type)(enum bpf_prog_type, __u32);
const char* (*sym_bpf_program__name)(const struct bpf_program *);
int dlopen_bpf(void) {
- _cleanup_(dlclosep) void *dl = NULL;
- int r;
-
- if (bpf_dl)
- return 0; /* Already loaded */
-
- dl = dlopen("libbpf.so.0", RTLD_LAZY);
- if (!dl)
- return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "libbpf is not installed: %s", dlerror());
-
- r = dlsym_many_or_warn(
- dl,
- LOG_DEBUG,
+ return dlopen_many_sym_or_warn(
+ &bpf_dl, "libbpf.so.0", LOG_DEBUG,
DLSYM_ARG(bpf_link__destroy),
DLSYM_ARG(bpf_link__fd),
DLSYM_ARG(bpf_map__fd),
@@ -52,15 +40,7 @@ int dlopen_bpf(void) {
DLSYM_ARG(bpf_probe_prog_type),
DLSYM_ARG(bpf_program__attach_cgroup),
DLSYM_ARG(bpf_program__name),
- DLSYM_ARG(libbpf_get_error),
- NULL);
- if (r < 0)
- return r;
-
- /* Note that we never release the reference here, because there's no real reason to, after all this
- * was traditionally a regular shared library dependency which lives forever too. */
- bpf_dl = TAKE_PTR(dl);
- return 1;
+ DLSYM_ARG(libbpf_get_error));
}
#else
diff --git a/src/shared/cryptsetup-util.c b/src/shared/cryptsetup-util.c
index 99c78f6858..b93f702aff 100644
--- a/src/shared/cryptsetup-util.c
+++ b/src/shared/cryptsetup-util.c
@@ -51,20 +51,10 @@ crypt_token_info (*sym_crypt_token_status)(struct crypt_device *cd, int token, c
int (*sym_crypt_volume_key_get)(struct crypt_device *cd, int keyslot, char *volume_key, size_t *volume_key_size, const char *passphrase, size_t passphrase_size);
int dlopen_cryptsetup(void) {
- _cleanup_(dlclosep) void *dl = NULL;
int r;
- if (cryptsetup_dl)
- return 0; /* Already loaded */
-
- dl = dlopen("libcryptsetup.so.12", RTLD_LAZY);
- if (!dl)
- return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "libcryptsetup support is not installed: %s", dlerror());
-
- r = dlsym_many_or_warn(
- dl,
- LOG_DEBUG,
+ r = dlopen_many_sym_or_warn(
+ &cryptsetup_dl, "libcryptsetup.so.12", LOG_DEBUG,
DLSYM_ARG(crypt_activate_by_passphrase),
#if HAVE_CRYPT_ACTIVATE_BY_SIGNED_KEY
DLSYM_ARG(crypt_activate_by_signed_key),
@@ -104,15 +94,10 @@ int dlopen_cryptsetup(void) {
DLSYM_ARG(crypt_token_max),
#endif
DLSYM_ARG(crypt_token_status),
- DLSYM_ARG(crypt_volume_key_get),
- NULL);
- if (r < 0)
+ DLSYM_ARG(crypt_volume_key_get));
+ if (r <= 0)
return r;
- /* Note that we never release the reference here, because there's no real reason to, after all this
- * was traditionally a regular shared library dependency which lives forever too. */
- cryptsetup_dl = TAKE_PTR(dl);
-
/* Redirect the default logging calls of libcryptsetup to our own logging infra. (Note that
* libcryptsetup also maintains per-"struct crypt_device" log functions, which we'll also set
* whenever allocating a "struct crypt_device" context. Why set both? To be defensive: maybe some
diff --git a/src/shared/idn-util.c b/src/shared/idn-util.c
index 63a9ebf99d..6dda3af54c 100644
--- a/src/shared/idn-util.c
+++ b/src/shared/idn-util.c
@@ -21,32 +21,11 @@ const char *(*sym_idn2_strerror)(int rc) = NULL;
int (*sym_idn2_to_unicode_8z8z)(const char * input, char ** output, int flags) = NULL;
int dlopen_idn(void) {
- _cleanup_(dlclosep) void *dl = NULL;
- int r;
-
- if (idn_dl)
- return 0; /* Already loaded */
-
- dl = dlopen("libidn2.so.0", RTLD_LAZY);
- if (!dl)
- return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "libidn2 support is not installed: %s", dlerror());
-
- r = dlsym_many_or_warn(
- dl,
- LOG_DEBUG,
+ return dlopen_many_sym_or_warn(
+ &idn_dl, "libidn2.so.0", LOG_DEBUG,
DLSYM_ARG(idn2_lookup_u8),
DLSYM_ARG(idn2_strerror),
- DLSYM_ARG(idn2_to_unicode_8z8z),
- NULL);
- if (r < 0)
- return r;
-
- /* Note that we never release the reference here, because there's no real reason to, after all this
- * was traditionally a regular shared library dependency which lives forever too. */
- idn_dl = TAKE_PTR(dl);
-
- return 1;
+ DLSYM_ARG(idn2_to_unicode_8z8z));
}
#endif
diff --git a/src/shared/libfido2-util.c b/src/shared/libfido2-util.c
index c69943262d..12c644dcfc 100644
--- a/src/shared/libfido2-util.c
+++ b/src/shared/libfido2-util.c
@@ -61,20 +61,8 @@ int (*sym_fido_dev_open)(fido_dev_t *, const char *) = NULL;
const char* (*sym_fido_strerr)(int) = NULL;
int dlopen_libfido2(void) {
- _cleanup_(dlclosep) void *dl = NULL;
- int r;
-
- if (libfido2_dl)
- return 0; /* Already loaded */
-
- dl = dlopen("libfido2.so.1", RTLD_LAZY);
- if (!dl)
- return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "libfido2 support is not installed: %s", dlerror());
-
- r = dlsym_many_or_warn(
- dl,
- LOG_DEBUG,
+ return dlopen_many_sym_or_warn(
+ &libfido2_dl, "libfido2.so.1", LOG_DEBUG,
DLSYM_ARG(fido_assert_allow_cred),
DLSYM_ARG(fido_assert_free),
DLSYM_ARG(fido_assert_hmac_secret_len),
@@ -118,15 +106,7 @@ int dlopen_libfido2(void) {
DLSYM_ARG(fido_dev_make_cred),
DLSYM_ARG(fido_dev_new),
DLSYM_ARG(fido_dev_open),
- DLSYM_ARG(fido_strerr),
- NULL);
- if (r < 0)
- return r;
-
- /* Note that we never release the reference here, because there's no real reason to, after all this
- * was traditionally a regular shared library dependency which lives forever too. */
- libfido2_dl = TAKE_PTR(dl);
- return 1;
+ DLSYM_ARG(fido_strerr));
}
static int verify_features(
diff --git a/src/shared/pwquality-util.c b/src/shared/pwquality-util.c
index d7776e7eff..12efe62608 100644
--- a/src/shared/pwquality-util.c
+++ b/src/shared/pwquality-util.c
@@ -24,20 +24,8 @@ int (*sym_pwquality_set_int_value)(pwquality_settings_t *pwq, int setting, int v
const char* (*sym_pwquality_strerror)(char *buf, size_t len, int errcode, void *auxerror);
int dlopen_pwquality(void) {
- _cleanup_(dlclosep) void *dl = NULL;
- int r;
-
- if (pwquality_dl)
- return 0; /* Already loaded */
-
- dl = dlopen("libpwquality.so.1", RTLD_LAZY);
- if (!dl)
- return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "libpwquality support is not installed: %s", dlerror());
-
- r = dlsym_many_or_warn(
- dl,
- LOG_DEBUG,
+ return dlopen_many_sym_or_warn(
+ &pwquality_dl, "libpwquality.so.1", LOG_DEBUG,
DLSYM_ARG(pwquality_check),
DLSYM_ARG(pwquality_default_settings),
DLSYM_ARG(pwquality_free_settings),
@@ -45,15 +33,7 @@ int dlopen_pwquality(void) {
DLSYM_ARG(pwquality_get_str_value),
DLSYM_ARG(pwquality_read_config),
DLSYM_ARG(pwquality_set_int_value),
- DLSYM_ARG(pwquality_strerror),
- NULL);
- if (r < 0)
- return r;
-
- /* Note that we never release the reference here, because there's no real reason to, after all this
- * was traditionally a regular shared library dependency which lives forever too. */
- pwquality_dl = TAKE_PTR(dl);
- return 1;
+ DLSYM_ARG(pwquality_strerror));
}
void pwq_maybe_disable_dictionary(pwquality_settings_t *pwq) {
diff --git a/src/shared/qrcode-util.c b/src/shared/qrcode-util.c
index 5345b7288b..db48c73610 100644
--- a/src/shared/qrcode-util.c
+++ b/src/shared/qrcode-util.c
@@ -5,9 +5,9 @@
#if HAVE_QRENCODE
#include <qrencode.h>
-#include "alloc-util.h"
#include "dlfcn-util.h"
#include "locale-util.h"
+#include "log.h"
#include "terminal-util.h"
#define ANSI_WHITE_ON_BLACK "\033[40;37;1m"
@@ -18,30 +18,10 @@ static QRcode* (*sym_QRcode_encodeString)(const char *string, int version, QRecL
static void (*sym_QRcode_free)(QRcode *qrcode) = NULL;
int dlopen_qrencode(void) {
- _cleanup_(dlclosep) void *dl = NULL;
- int r;
-
- if (qrcode_dl)
- return 0; /* Already loaded */
-
- dl = dlopen("libqrencode.so.4", RTLD_LAZY);
- if (!dl)
- return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "libqrcode support is not installed: %s", dlerror());
-
- r = dlsym_many_or_warn(
- dl,
- LOG_DEBUG,
+ return dlopen_many_sym_or_warn(
+ &qrcode_dl, "libqrencode.so.4", LOG_DEBUG,
DLSYM_ARG(QRcode_encodeString),
- DLSYM_ARG(QRcode_free),
- NULL);
- if (r < 0)
- return r;
-
- /* Note that we never release the reference here, because there's no real reason to, after all this
- * was traditionally a regular shared library dependency which lives forever too. */
- qrcode_dl = TAKE_PTR(dl);
- return 1;
+ DLSYM_ARG(QRcode_free));
}
static void print_border(FILE *output, unsigned width) {