summaryrefslogtreecommitdiffstats
path: root/src/basic/dlfcn-util.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 13:00:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 13:00:47 +0000
commit2cb7e0aaedad73b076ea18c6900b0e86c5760d79 (patch)
treeda68ca54bb79f4080079bf0828acda937593a4e1 /src/basic/dlfcn-util.c
parentInitial commit. (diff)
downloadsystemd-2cb7e0aaedad73b076ea18c6900b0e86c5760d79.tar.xz
systemd-2cb7e0aaedad73b076ea18c6900b0e86c5760d79.zip
Adding upstream version 247.3.upstream/247.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/basic/dlfcn-util.c')
-rw-r--r--src/basic/dlfcn-util.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/basic/dlfcn-util.c b/src/basic/dlfcn-util.c
new file mode 100644
index 0000000..2dbff0e
--- /dev/null
+++ b/src/basic/dlfcn-util.c
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "dlfcn-util.h"
+
+int dlsym_many_and_warn(void *dl, int level, ...) {
+ va_list ap;
+ int r;
+
+ /* Tries to resolve a bunch of function symbols, and logs errors about the ones it cannot
+ * resolve. Note that this function possibly modifies the supplied function pointers if the whole
+ * operation fails */
+
+ va_start(ap, level);
+
+ for (;;) {
+ void (**fn)(void);
+ void (*tfn)(void);
+ const char *symbol;
+
+ fn = va_arg(ap, typeof(fn));
+ if (!fn)
+ break;
+
+ symbol = va_arg(ap, typeof(symbol));
+
+ tfn = (typeof(tfn)) dlsym(dl, symbol);
+ if (!tfn) {
+ r = log_full_errno(level,
+ SYNTHETIC_ERRNO(ELIBBAD),
+ "Can't find symbol %s: %s", symbol, dlerror());
+ va_end(ap);
+ return r;
+ }
+
+ *fn = tfn;
+ }
+
+ va_end(ap);
+ return 0;
+}