Skip to content

Commit

Permalink
prov/cxi: Add FI_CXI_CURL_LIB_PATH #define from autoconf
Browse files Browse the repository at this point in the history
This ensures that the libcurl dlopen path is correct

If the user passes '--with-curl=<path>' to configure, then the dlopen of
libcurl should honor that selection and use the file path passed in

Signed-off-by: John Biddiscombe <[email protected]>
  • Loading branch information
biddisco committed Jan 20, 2025
1 parent 77afcaf commit d59bc9f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
4 changes: 3 additions & 1 deletion prov/cxi/configure.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
48 changes: 32 additions & 16 deletions prov/cxi/src/cxip_curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,28 +189,44 @@ 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++) {
sprintf(libfile, 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);
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);
continue;
}
TRACE_CURL("%s found\n", libpath);
free(libpath);
continue;
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");
Expand Down

0 comments on commit d59bc9f

Please sign in to comment.