From: Alan T. DeKok Date: Sun, 19 Jun 2011 08:37:44 +0000 (+0200) Subject: More hacks to make dlopen() work natively X-Git-Tag: release_3_0_0_beta0~763 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab437b595b3326f1b2f9bbce7465c3ebce4f24d2;p=thirdparty%2Ffreeradius-server.git More hacks to make dlopen() work natively --- diff --git a/src/include/modpriv.h b/src/include/modpriv.h index 43a414d29a0..b00d3ad8dec 100644 --- a/src/include/modpriv.h +++ b/src/include/modpriv.h @@ -26,13 +26,13 @@ extern "C" { #ifdef WITHOUT_LIBLTDL typedef void *lt_dlhandle; +int lt_dlinit(void); lt_dlhandle lt_dlopenext(const char *name); void *lt_dlsym(lt_dlhandle handle, const char *symbol); int lt_dlclose(lt_dlhandle handle); const char *lt_dlerror(void); #define LTDL_SET_PRELOADED_SYMBOLS(_x) -#define lt_dlinit(_x) (0) #define lt_dlexit(_x) #define lt_dlsetsearchpath(_x) #endif diff --git a/src/main/modules.c b/src/main/modules.c index 18a1b29026d..ab3e61263a1 100644 --- a/src/main/modules.c +++ b/src/main/modules.c @@ -107,17 +107,46 @@ static const section_type_value_t section_type_value[RLM_COMPONENT_COUNT] = { #define fr_dlopenext lt_dlopenext #ifndef LT_SHREXT #ifdef __APPLE__ -#define LT_SHREXT ".so" +#define LT_SHREXT ".dylib" +#define LD_LIBRARY_PATH "DYLD_FALLBACK_LIBRARY_PATH" #elif defined (WIN32) #define LT_SHREXT ".dll" #else -#define LT_SHREXT ".dylib" +#define LT_SHREXT ".so" +#define LD_LIBRARY_PATH "LD_LIBRARY_PATH" #endif #endif +int lt_dlinit(void) +{ + char *p, *val; + char buffer[1024]; + + /* + * This doesn't really do anything... + */ + p = getenv(LD_LIBRARY_PATH); + if (p) { + snprintf(buffer, sizeof(buffer), "%s:%s", p, radlib_dir); + val = buffer; + } else { + val = radlib_dir; + } + + return setenv(LD_LIBRARY_PATH, val, 1); +} + lt_dlhandle lt_dlopenext(const char *name) { - char buffer[256]; + void *handle; + char buffer[2048]; + + /* + * Prefer loading our libraries by absolute path. + */ + snprintf(buffer, sizeof(buffer), "%s/%s%s", radlib_dir, name, LT_SHREXT); + handle = dlopen(buffer, RTLD_NOW | RTLD_LOCAL); + if (handle) return handle; strlcpy(buffer, name, sizeof(buffer));