]> git.proxmox.com Git - mirror_kronosnet.git/commitdiff
[common] Conditionalize RTLD_DI_ORIGIN
authorJan Friesse <jfriesse@redhat.com>
Mon, 2 Sep 2019 09:11:27 +0000 (11:11 +0200)
committerJan Friesse <jfriesse@redhat.com>
Tue, 3 Sep 2019 07:48:29 +0000 (09:48 +0200)
RTLD_DI_ORIGIN is used to get absolute path of plugin. It is used only
for logging useful info and not strictly needed, so use it only when it
is defined (only musl is known to author of the patch)

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
configure.ac
libknet/common.c

index 778b12a5bac52fe28bb88ddef55b815d2bd14abf..e430aeb80f0f8f3fce30fb07c851e8332b52f67b 100644 (file)
@@ -205,6 +205,10 @@ AC_SEARCH_LIBS([dlopen], [dl dld], , [AC_MSG_ERROR([dlopen not found])])
 AC_SUBST([dl_LIBS], [$LIBS])
 LIBS="$saved_LIBS"
 
+# Check RTLD_DI_ORIGIN (not decalred by musl. glibc has it as an enum so cannot use ifdef)
+AC_CHECK_DECL([RTLD_DI_ORIGIN], [AC_DEFINE([HAVE_RTLD_DI_ORIGIN], 1,
+    [define when RTLD_DI_ORIGIN is declared])], ,[[#include <dlfcn.h>]])
+
 # OS detection
 
 AC_MSG_CHECKING([for os in ${host_os}])
index 00907c91f1560f1625c831f7deb84e0b71c8847b..ed8ac8991703d30932ff748615f7a939b93eff00 100644 (file)
@@ -12,6 +12,8 @@
 #include <fcntl.h>
 #include <dlfcn.h>
 #include <errno.h>
+#include <libgen.h>
+#include <link.h>
 #include <string.h>
 #include <sys/param.h>
 #include <sys/types.h>
@@ -54,6 +56,30 @@ int _fdset_nonblock(int fd)
        return 0;
 }
 
+static int get_lib_dir(void *lib_handle, char dir[MAXPATHLEN])
+{
+       int res;
+#ifndef HAVE_RTLD_DI_ORIGIN
+       struct link_map *lm;
+       char l_name[MAXPATHLEN];
+#endif
+
+#ifdef HAVE_RTLD_DI_ORIGIN
+       res = dlinfo(lib_handle, RTLD_DI_ORIGIN, dir);
+#else
+       /*
+        * musl libc doesn't support RTLD_DI_ORIGIN
+        */
+       res = dlinfo(lib_handle, RTLD_DI_LINKMAP, &lm);
+       if (res == 0) {
+               snprintf(l_name, sizeof(l_name), "%s", lm->l_name);
+               snprintf(dir, MAXPATHLEN, "%s", dirname(l_name));
+       }
+#endif
+
+       return res;
+}
+
 static void *open_lib(knet_handle_t knet_h, const char *libname, int extra_flags)
 {
        void *ret = NULL;
@@ -81,7 +107,7 @@ static void *open_lib(knet_handle_t knet_h, const char *libname, int extra_flags
        memset(dir, 0, sizeof(dir));
        memset(link, 0, sizeof(link));
        memset(path, 0, sizeof(path));
-       if (dlinfo(ret, RTLD_DI_ORIGIN, &dir) < 0) {
+       if (get_lib_dir(ret, dir) < 0) {
                /*
                 * should we dlclose and return error?
                 */