1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
/*
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2016 IBM Corporation. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/constants.h"
#include "opal/mca/dl/dl.h"
#include "dl_libltdl.h"
static int libltdl_open(const char *fname, bool use_ext, bool private_namespace,
opal_dl_handle_t **handle, char **err_msg)
{
assert(handle);
*handle = NULL;
if (NULL != err_msg) {
*err_msg = NULL;
}
lt_dlhandle local_handle;
#if OPAL_DL_LIBLTDL_HAVE_LT_DLADVISE
opal_dl_libltdl_component_t *c = &mca_dl_libltdl_component;
if (use_ext && private_namespace) {
local_handle = lt_dlopenadvise(fname, c->advise_private_ext);
} else if (use_ext && !private_namespace) {
local_handle = lt_dlopenadvise(fname, c->advise_public_ext);
} else if (!use_ext && private_namespace) {
local_handle = lt_dlopenadvise(fname, c->advise_private_noext);
} else if (!use_ext && !private_namespace) {
local_handle = lt_dlopenadvise(fname, c->advise_public_noext);
}
#else
if (use_ext) {
local_handle = lt_dlopenext(fname);
} else {
local_handle = lt_dlopen(fname);
}
#endif
if (NULL != local_handle) {
*handle = calloc(1, sizeof(opal_dl_handle_t));
(*handle)->ltdl_handle = local_handle;
#if OPAL_ENABLE_DEBUG
if( NULL != fname ) {
(*handle)->filename = strdup(fname);
}
else {
(*handle)->filename = strdup("(null)");
}
#endif
return OPAL_SUCCESS;
}
if (NULL != err_msg) {
*err_msg = (char*) lt_dlerror();
}
return OPAL_ERROR;
}
static int libltdl_lookup(opal_dl_handle_t *handle, const char *symbol,
void **ptr, char **err_msg)
{
assert(handle);
assert(handle->ltdl_handle);
assert(symbol);
assert(ptr);
if (NULL != err_msg) {
*err_msg = NULL;
}
*ptr = lt_dlsym(handle->ltdl_handle, symbol);
if (NULL != *ptr) {
return OPAL_SUCCESS;
}
if (NULL != err_msg) {
*err_msg = (char*) lt_dlerror();
}
return OPAL_ERROR;
}
static int libltdl_close(opal_dl_handle_t *handle)
{
assert(handle);
int ret;
ret = lt_dlclose(handle->ltdl_handle);
#if OPAL_ENABLE_DEBUG
free(handle->filename);
#endif
free(handle);
return ret;
}
static int libltdl_foreachfile(const char *search_path,
int (*func)(const char *filename, void *data),
void *data)
{
assert(search_path);
assert(func);
int ret = lt_dlforeachfile(search_path, func, data);
return (0 == ret) ? OPAL_SUCCESS : OPAL_ERROR;
}
/*
* Module definition
*/
opal_dl_base_module_t opal_dl_libltdl_module = {
.open = libltdl_open,
.lookup = libltdl_lookup,
.close = libltdl_close,
.foreachfile = libltdl_foreachfile
};
|