Template code to use lt_dladvise()
authorAlan T. DeKok <aland@freeradius.org>
Wed, 9 Dec 2009 14:48:30 +0000 (15:48 +0100)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 9 Dec 2009 14:50:31 +0000 (15:50 +0100)
The libtool people have discovered that it's useful to allow
*additional* features from linking.  Like allowing libraries to
link to libraries.  Using this magic API allows FreeRADIUS to load
the Perl module, which in turn loads other modules, which in turn
load dynamic libraries.  Right now, it complains because of
limitations in libltdl.

We COULD do these checks in 2.1.8, but that involves either adding
configure checks, OR upgrading our version of libltdl.  We don't want
to do either.

src/main/modules.c

index ea1c256..44cd7c6 100644 (file)
@@ -201,6 +201,31 @@ const char *lt_dlerror(void)
 }
 
 #endif /* WITH_DLOPEN */
+#else  /* WITHOUT_LIBLTDL */
+
+/*
+ *     Solve the issues of libraries linking to other libraries
+ *     by using a newer libltdl API.
+ */
+#ifndef HAVE_LT_DLADVISE_INIT
+#define fr_dlopenext lt_dlopenext
+#else
+static lt_dlhandle fr_dlopenext(const char *filename)
+{
+       lt_dlhandle handle = 0;
+       lt_dladvise advise;
+
+       if (!lt_dladvise_init (&advise) &&
+           !lt_dladvise_ext (&advise) &&
+           !lt_dladvise_global (&advise)) {
+               handle = lt_dlopenadvise (filename, advise);
+       }
+
+       lt_dladvise_destroy (&advise);
+
+       return handle;
+}
+#endif /* HAVE_LT_DLADVISE_INIT */
 #endif /* WITHOUT_LIBLTDL */
 
 static int virtual_server_idx(const char *name)
@@ -411,7 +436,7 @@ static module_entry_t *linkto_module(const char *module_name,
        /*
         *      Keep the handle around so we can dlclose() it.
         */
-       handle = lt_dlopenext(module_name);
+       handle = fr_dlopenext(module_name);
        if (handle == NULL) {
                cf_log_err(cf_sectiontoitem(cs),
                           "Failed to link to module '%s': %s\n",