journalctl: make libqrencode a weak dependency
This way journalctl can make use of libqrencode if it's there, but will quietly not use it if it isn't. This means libqrencode remains a build-time dep, but not a strict runtime dependency. I figure we should do something similar for a bunch of other "leaf" libraries we only use few symbols of. Specifically the following are probably good candidates: * pcre2 * libpwquality * p11kit * elfutils and possibly: * libcryptsetup (only in some parts. i.e. building systemd-cryptsetup without it makes no sense. However building the dissect option with libcryptsetup as optional dep does make sense) * possibly the compression libraries (at least the ones we never use for compression, but only as alternative ones for decompression) Already covered like this is: * libxkcommon
This commit is contained in:
parent
a4df1f0b9d
commit
e44b500484
|
@ -1780,7 +1780,7 @@ public_programs += executable(
|
|||
include_directories : includes,
|
||||
link_with : [libshared],
|
||||
dependencies : [threads,
|
||||
libqrencode,
|
||||
libdl,
|
||||
libxz,
|
||||
liblz4,
|
||||
libpcre2,
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "dlfcn-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "journal-qrcode.h"
|
||||
|
@ -40,6 +41,9 @@ int print_qr_code(
|
|||
const char *hn,
|
||||
sd_id128_t machine) {
|
||||
|
||||
QRcode* (*sym_QRcode_encodeString)(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive);
|
||||
void (*sym_QRcode_free)(QRcode *qrcode);
|
||||
_cleanup_(dlclosep) void *dl = NULL;
|
||||
_cleanup_free_ char *url = NULL;
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
size_t url_size = 0, i;
|
||||
|
@ -55,6 +59,20 @@ int print_qr_code(
|
|||
if (!is_locale_utf8() || !colors_enabled())
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
dl = dlopen("libqrencode.so.4", RTLD_LAZY);
|
||||
if (!dl)
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
|
||||
"QRCODE support is not installed: %s", dlerror());
|
||||
|
||||
r = dlsym_many_and_warn(
|
||||
dl,
|
||||
LOG_DEBUG,
|
||||
&sym_QRcode_encodeString, "QRcode_encodeString",
|
||||
&sym_QRcode_free, "QRcode_free",
|
||||
NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
f = open_memstream_unlocked(&url, &url_size);
|
||||
if (!f)
|
||||
return -ENOMEM;
|
||||
|
@ -81,7 +99,7 @@ int print_qr_code(
|
|||
|
||||
f = safe_fclose(f);
|
||||
|
||||
qr = QRcode_encodeString(url, 0, QR_ECLEVEL_L, QR_MODE_8, 1);
|
||||
qr = sym_QRcode_encodeString(url, 0, QR_ECLEVEL_L, QR_MODE_8, 1);
|
||||
if (!qr)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -123,6 +141,6 @@ int print_qr_code(
|
|||
|
||||
print_border(output, qr->width);
|
||||
|
||||
QRcode_free(qr);
|
||||
sym_QRcode_free(qr);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue