]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journalctl: make libqrencode a weak dependency 16145/head
authorLennart Poettering <lennart@poettering.net>
Thu, 11 Jun 2020 11:16:53 +0000 (13:16 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 25 Jun 2020 07:28:27 +0000 (09:28 +0200)
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

meson.build
src/journal/journal-qrcode.c

index 8f1d1b58971beb6b017065a2d17e5fdc1dd909cb..3a869679380dfcc7377cdc67c4262bfc625ef7fe 100644 (file)
@@ -1780,7 +1780,7 @@ public_programs += executable(
         include_directories : includes,
         link_with : [libshared],
         dependencies : [threads,
-                        libqrencode,
+                        libdl,
                         libxz,
                         liblz4,
                         libpcre2,
index 706d33c38a97995bd0c466259654b4e969521414..dddbd7b3813fa65e5e7967fa8e94e762bb295378 100644 (file)
@@ -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;
 }