]> granicus.if.org Git - libnl/commitdiff
build: allow building cli without dynamic librarires support
authorThomas Haller <thaller@redhat.com>
Fri, 12 May 2017 10:47:19 +0000 (12:47 +0200)
committerThomas Haller <thaller@redhat.com>
Fri, 12 May 2017 10:57:34 +0000 (12:57 +0200)
Commit 3cb28534d34392ceec4adead0cfa97039796ccb7 enables building
of cli always as part of `make check`. As cli previously always
included <dlfcn.h>, this broke tests for building with toolchains
that don't support dynamic library loading.

Add a configure check and disable dlopen() based on whether
<dlfcn.h> is available.

Signed-off-by: Thomas Haller <thaller@redhat.com>
https://github.com/thom311/libnl/pull/141

configure.ac
include/netlink/cli/utils.h
src/lib/utils.c

index e7402fdf0b9f494b516059a2d0575cfde3940de1..387a53b46b38f0a0a62df3eb8e7dd59b3fcbc6b7 100644 (file)
@@ -101,6 +101,8 @@ AM_CONDITIONAL([ENABLE_CLI], [test "$enable_cli" != "no"])
 AM_CONDITIONAL([ENABLE_CLI_INSTALL_BIN], [test "$enable_cli" = "bin"])
 AM_CONDITIONAL([ENABLE_CLI_INSTALL_SBIN], [test "$enable_cli" = "sbin"])
 
+AC_CHECK_HEADERS(dlfcn.h, [], [])
+
 AC_ARG_ENABLE([pthreads],
        AS_HELP_STRING([--disable-pthreads], [Disable pthreads support]),
        [enable_pthreads="$enableval"], [enable_pthreads="yes"])
index 4c28343790ad73870c346915564dd7eae0a87c35..a76fce28cf6cb15ba8032a5149860daab3c3cb9a 100644 (file)
@@ -22,7 +22,6 @@
 #include <stdint.h>
 #include <ctype.h>
 #include <getopt.h>
-#include <dlfcn.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 
index feb1d4ef4056ebab0e3f36bfe9acb9e91c8ecc93..6e288b6081ffcf575b5e7e0b099553832a3e5e00 100644 (file)
 #include <netlink/cli/utils.h>
 #include <locale.h>
 
+#include "lib/defs.h"
+
+#ifdef HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
 /**
  * Parse a text based 32 bit unsigned integer argument
  * @arg arg            Integer in text form.
@@ -220,14 +226,23 @@ struct nl_cache *nl_cli_alloc_cache_flags(struct nl_sock *sock,
 void nl_cli_load_module(const char *prefix, const char *name)
 {
        char path[FILENAME_MAX+1];
-       void *handle;
 
        snprintf(path, sizeof(path), "%s/%s/%s.so",
                 PKGLIBDIR, prefix, name);
 
-       if (!(handle = dlopen(path, RTLD_NOW)))
-               nl_cli_fatal(ENOENT, "Unable to load module \"%s\": %s\n",
-                       path, dlerror());
+#ifdef HAVE_DLFCN_H
+       {
+               void *handle;
+
+               if (!(handle = dlopen(path, RTLD_NOW))) {
+                       nl_cli_fatal(ENOENT, "Unable to load module \"%s\": %s\n",
+                                    path, dlerror());
+               }
+       }
+#else
+       nl_cli_fatal(ENOTSUP, "Unable to load module \"%s\": built without dynamic libraries support\n",
+                    path);
+#endif
 }
 
 /** @} */