root/opal/mca/pmix/pmix4x/pmix/src/mca/pdl/plibltdl/pdl_libltdl_module.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. plibltpdl_open
  2. plibltpdl_lookup
  3. plibltpdl_close
  4. plibltpdl_foreachfile

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

/* [<][>][^][v][top][bottom][index][help] */