]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: add dlfcn-util.h
authorLennart Poettering <lennart@poettering.net>
Thu, 4 Jun 2020 09:25:46 +0000 (11:25 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 23 Jun 2020 15:23:27 +0000 (17:23 +0200)
This just adds a _cleanup_ helper call encapsulating dlclose().

This also means libsystemd-shared is linked against libdl now. I don't
think this is much of an issue, since libdl is part of glibc anyway, and
anything from exotic. It's not an optional part of the OS (think: NSS
requires dynamic linking), hence this pulls in no deps and is almost
certainly loaded into all process' memory anyway.

[zj: use DEFINE_TRIVIAL_CLEANUP_FUNC().]

src/basic/dlfcn-util.h [new file with mode: 0644]
src/basic/meson.build
src/locale/localed.c
src/locale/meson.build

diff --git a/src/basic/dlfcn-util.h b/src/basic/dlfcn-util.h
new file mode 100644 (file)
index 0000000..d254afb
--- /dev/null
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+#pragma once
+
+#include <dlfcn.h>
+
+#include "macro.h"
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(void*, dlclose);
index 5bb49ef4014b2cd9aa9008cc408fd21a00387c61..90924d6cb895525e1becade481fff0eb5a6600b6 100644 (file)
@@ -39,6 +39,7 @@ basic_sources = files('''
         device-nodes.h
         dirent-util.c
         dirent-util.h
+        dlfcn-util.h
         efivars.c
         efivars.h
         env-file.c
@@ -328,7 +329,8 @@ libbasic = static_library(
                         threads,
                         libcap,
                         libselinux,
-                        libm],
+                        libm,
+                        libdl],
         c_args : ['-fvisibility=default'],
         install : false)
 
index 8ffcf306b5b74aec4de5593f0ea8e86d2e403e5b..b946060b242ff523df0d26e705d73bc01e7dfe36 100644 (file)
@@ -18,6 +18,7 @@
 #include "bus-message.h"
 #include "bus-polkit.h"
 #include "def.h"
+#include "dlfcn-util.h"
 #include "keymap-util.h"
 #include "locale-util.h"
 #include "macro.h"
@@ -530,7 +531,7 @@ static int verify_xkb_rmlvo(const char *model, const char *layout, const char *v
         };
         struct xkb_context *ctx = NULL;
         struct xkb_keymap *km = NULL;
-        void *dl;
+        _cleanup_(dlclosep) void *dl = NULL;
         int r;
 
         /* Compile keymap from RMLVO information to check out its validity */
@@ -582,7 +583,6 @@ finish:
         if (symbol_xkb_context_unref && ctx)
                 symbol_xkb_context_unref(ctx);
 
-        (void) dlclose(dl);
         return r;
 }
 
index e87a10ebeb51fbfc08628b4bf2ef7b61c8a61b59..314b0a3d3799de5c2bdf97790962a0999f5e9f5b 100644 (file)
@@ -34,5 +34,5 @@ tests += [
           'src/locale/keymap-util.c',
           'src/locale/keymap-util.h'],
          [libshared],
-         [libdl]],
+         []],
 ]