diff --git a/prov/cxi/configure.m4 b/prov/cxi/configure.m4 index ec76590ca2e..cab843f47a2 100644 --- a/prov/cxi/configure.m4 +++ b/prov/cxi/configure.m4 @@ -35,8 +35,10 @@ AC_DEFUN([FI_CXI_CONFIGURE],[ [CPPFLAGS="-I$with_cxi_uapi_headers/include $CPPFLAGS"]) # Support non-standard install path for curl. This is needed by CXI provider. + # Add #define of the path to the curl library for use in the code AC_ARG_WITH([curl], - [AS_HELP_STRING([--with-curl=DIR], [Install directory for curl])]) + [AS_HELP_STRING([--with-curl=DIR], [Install directory for curl])], + [AC_DEFINE_UNQUOTED([FI_CXI_CURL_LIB_PATH], ["$with_curl"], [Path to the curl install root])]) # Support non-standard install path for json-c. This is needed by CXI provider. AC_ARG_WITH([json-c], diff --git a/prov/cxi/src/cxip_curl.c b/prov/cxi/src/cxip_curl.c index e849ebad806..f3954327651 100644 --- a/prov/cxi/src/cxip_curl.c +++ b/prov/cxi/src/cxip_curl.c @@ -180,7 +180,7 @@ struct curlfunc curlary[] = { int cxip_curl_load_symbols(void) { struct curlfunc *funcptr; - char libfile[256], *libpath; + char *libfile = NULL, *libpath; int version; int errcnt; void *h; @@ -189,28 +189,53 @@ int cxip_curl_load_symbols(void) if (cxip_curlhandle) return 0; + char *curl_libpath = NULL; + #ifdef FI_CXI_CURL_LIB_PATH + curl_libpath = strdup(FI_CXI_CURL_LIB_PATH "/%s/libcurl.so.%d"); + TRACE_CURL("FI_CXI_CURL_LIB_PATH set to '%s'\n", curl_libpath); + #else + curl_libpath = strdup("/usr/%s/libcurl.so.%d"); + #endif + /* Try to find latest usable version */ // TODO test earlier versions for (version = 4; version >= 4; version--) { - sprintf(libfile, "/usr/lib64/libcurl.so.%d", version); - libpath = realpath(libfile, NULL); - if (!libpath) { - TRACE_CURL("could not expand '%s'\n", libfile); - CXIP_INFO("could not expand '%s'\n", libfile); - continue; - } - TRACE_CURL("dlopen '%s'\n", libpath); - h = dlopen(libpath, RTLD_NOW); - if (!h) { - TRACE_CURL("%s not found\n", libpath); - CXIP_INFO("%s not found\n", libpath); + const char *lib_dirs[] = {"lib", "lib64"}; + for (int i = 0; i < 2; i++) { + int len = snprintf(NULL, 0, curl_libpath, lib_dirs[i], version) + 1; + libfile = malloc(len); + if (!libfile) { + free(curl_libpath); + return -FI_ENOMEM; + } + snprintf(libfile, len, curl_libpath, lib_dirs[i], version); + TRACE_CURL("Checking libcurl at '%s'\n", libfile); + libpath = realpath(libfile, NULL); + if (!libpath) { + TRACE_CURL("could not expand '%s'\n", libfile); + CXIP_INFO("could not expand '%s'\n", libfile); + free(libfile); + continue; + } + TRACE_CURL("dlopen '%s'\n", libpath); + h = dlopen(libpath, RTLD_NOW); + if (!h) { + TRACE_CURL("%s not found\n", libpath); + CXIP_INFO("%s not found\n", libpath); + free(libpath); + free(libfile); + continue; + } + TRACE_CURL("%s found\n", libpath); free(libpath); - continue; + free(libfile); + break; + } + if (h) { + break; } - TRACE_CURL("%s found\n", libpath); - free(libpath); - break; } + free(curl_libpath); if (!h) { TRACE_CURL("libcurl not supported\n"); CXIP_WARN("libcurl not supported\n");