From: Arran Cudbard-Bell Date: Wed, 7 Oct 2015 02:34:12 +0000 (-0400) Subject: Fix tests on macs running in rootless mode X-Git-Tag: release_3_0_11~282 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9181a0a305a1aa7ed4d617fdc6e16eb7208248e8;p=thirdparty%2Ffreeradius-server.git Fix tests on macs running in rootless mode Die Apple die... --- diff --git a/Make.inc.in b/Make.inc.in index a06a044bc28..a69a2538d28 100644 --- a/Make.inc.in +++ b/Make.inc.in @@ -163,7 +163,7 @@ ANALYZE.c := @clang_path@ # ifeq "$(USE_SHARED_LIBS)" "yes" TESTBINDIR = ./$(BUILD_DIR)/bin/local - TESTBIN = $(JLIBTOOL) --quiet --mode=execute $(TESTBINDIR) + TESTBIN = FR_LIBRARY_PATH=./build/lib/.libs $(JLIBTOOL) --quiet --mode=execute $(TESTBINDIR) else TESTBINDIR = ./$(BUILD_DIR)/bin TESTBIN = ./$(BUILD_DIR)/bin diff --git a/Makefile b/Makefile index bc0150f6e0b..219e55d4335 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ raddb/test.conf: $(BUILD_DIR)/tests/radiusd-c: raddb/test.conf ${BUILD_DIR}/bin/radiusd | build.raddb @$(MAKE) -C raddb/certs @printf "radiusd -C... " - @if ! ./build/make/jlibtool --mode=execute ./build/bin/radiusd -XCMd ./raddb -D ./share -n test > $(BUILD_DIR)/tests/radiusd.config.log; then \ + @if ! FR_LIBRARY_PATH=./build/lib/local/.libs/ ./build/make/jlibtool --mode=execute ./build/bin/radiusd -XCMd ./raddb -D ./share -n test > $(BUILD_DIR)/tests/radiusd.config.log; then \ rm -f raddb/test.conf; \ cat $(BUILD_DIR)/tests/radiusd.config.log; \ echo "fail"; \ @@ -59,7 +59,7 @@ test: ${BUILD_DIR}/bin/radiusd ${BUILD_DIR}/bin/radclient tests.unit tests.xlat #  the above tests ifneq "$(findstring travis,${prefix})" "" travis-test: raddb/test.conf test - @./build/make/jlibtool --mode=execute ./build/bin/radiusd -xxxv -n test + @FR_LIBRARY_PATH=./build/lib/local/.libs/ ./build/make/jlibtool --mode=execute ./build/bin/radiusd -xxxv -n test @rm -f raddb/test.conf @$(MAKE) install @perl -p -i -e 's/allow_vulnerable_openssl = no/allow_vulnerable_openssl = yes/' ${raddbdir}/radiusd.conf diff --git a/src/main/modules.c b/src/main/modules.c index 6053e0e9e80..b21ee8943e6 100644 --- a/src/main/modules.c +++ b/src/main/modules.c @@ -30,6 +30,11 @@ RCSID("$Id$") #include #include +/** Path to search for modules in + * + */ +char const *radlib_dir = NULL; + typedef struct indexed_modcallable { rlm_components_t comp; int idx; @@ -152,11 +157,11 @@ static int check_module_magic(CONF_SECTION *cs, module_t const *module) lt_dlhandle lt_dlopenext(char const *name) { - int flags = RTLD_NOW; - void *handle; - char buffer[2048]; - char *env; - + int flags = RTLD_NOW; + void *handle; + char buffer[2048]; + char *env; + char const *search_path; #ifdef RTLD_GLOBAL if (strcmp(name, "rlm_perl") == 0) { flags |= RTLD_GLOBAL; @@ -170,42 +175,53 @@ lt_dlhandle lt_dlopenext(char const *name) */ flags |= RTLD_NOW; #endif + + /* + * Apple removed support for DYLD_LIBRARY_PATH in rootless mode. + */ + env = getenv("FR_LIBRARY_PATH"); + if (env) { + DEBUG3("Ignoring libdir as FR_LIBRARY_PATH set. Module search path will be: %s", env); + search_path = env; + } else { + search_path = radlib_dir; + } + /* * Prefer loading our libraries by absolute path. */ - if (radlib_dir) { + if (search_path) { char *error; + char *ctx, *paths, *path; + char *p; - snprintf(buffer, sizeof(buffer), "%s/%s%s", radlib_dir, name, LT_SHREXT); + fr_strerror(); - DEBUG4("Loading library using absolute path \"%s\"", buffer); + ctx = paths = talloc_strdup(NULL, search_path); + while ((path = strsep(&paths, ":")) != NULL) { + /* + * Trim the trailing slash + */ + p = strrchr(path, '/'); + if (p && ((p[1] == '\0') || (p[1] == ':'))) *p = '\0'; - handle = dlopen(buffer, flags); - if (handle) return handle; - error = dlerror(); + path = talloc_asprintf(ctx, "%s/%s%s", path, name, LT_SHREXT); - fr_strerror_printf("%s", error); - DEBUG4("Failed with error: %s", error); + DEBUG4("Loading %s with path: %s", name, path); - /* - * Because dlopen (on OSX at least) produces really - * shitty and inaccurate error messages - */ - if (access(buffer, R_OK) < 0) { - switch (errno) { - case EACCES: - WARN("Library file found, but we don't have permission to read it"); - break; - - case ENOENT: - DEBUG4("Library file not found"); - break; - - default: - DEBUG4("Issue accessing library file: %s", fr_syserror(errno)); - break; + handle = dlopen(path, flags); + if (handle) { + talloc_free(ctx); + return handle; } + error = dlerror(); + + fr_strerror_printf("%s%s\n", fr_strerror(), error); + DEBUG4("Loading %s failed: %s - %s", name, error, + (access(buffer, R_OK) < 0) ? fr_syserror(errno) : "No access errors"); + talloc_free(path); } + talloc_free(ctx); } DEBUG4("Loading library using linker search path(s)"); diff --git a/src/main/radiusd.c b/src/main/radiusd.c index 99ee4b5d2cd..fc29e28f353 100644 --- a/src/main/radiusd.c +++ b/src/main/radiusd.c @@ -57,7 +57,7 @@ RCSID("$Id$") char const *progname = NULL; char const *radacct_dir = NULL; char const *radlog_dir = NULL; -char const *radlib_dir = NULL; + bool log_stripped_names; char const *radiusd_version = "FreeRADIUS Version " RADIUSD_VERSION_STRING diff --git a/src/main/radwho.c b/src/main/radwho.c index 29c1a34d797..3cfff2902b6 100644 --- a/src/main/radwho.c +++ b/src/main/radwho.c @@ -53,7 +53,6 @@ static char const *raddb_dir = RADDBDIR; static char const *dict_dir = DICTDIR; char const *radacct_dir = NULL; -char const *radlib_dir = NULL; bool log_stripped_names; diff --git a/src/main/unittest.c b/src/main/unittest.c index 9952a8ad699..e0a301b71f6 100644 --- a/src/main/unittest.c +++ b/src/main/unittest.c @@ -40,7 +40,6 @@ RCSID("$Id$") char const *progname = NULL; char const *radacct_dir = NULL; char const *radlog_dir = NULL; -char const *radlib_dir = NULL; bool log_stripped_names = false; static bool memory_report = false;