From ae1144f8826dcecc68ec923bb7261f2a8153735c Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Fri, 21 Apr 2017 10:02:43 -0500 Subject: HDFFV-9655 fix compile and test --- src/H5PL.c | 82 +++++++++++++++++++++++++++++--------------------- test/CMakeTests.cmake | 6 ++++ test/test_plugin.sh.in | 33 ++++++++++++-------- 3 files changed, 74 insertions(+), 47 deletions(-) diff --git a/src/H5PL.c b/src/H5PL.c index 79aa156..0cdbc93 100644 --- a/src/H5PL.c +++ b/src/H5PL.c @@ -105,7 +105,9 @@ typedef const void *(*H5PL_get_plugin_info_t)(void); #define H5PL_NO_PLUGIN "::" /* Special symbol to indicate relative path from environment */ -#define H5PL_PLUGIN_ENV_SPECIALCHAR '@' +/* Restrict usage of special char only for the default path H5_DEFAULT_PLUGINDIR + * or when using the environment variable HDF5_PLUGIN_PATH */ +#define H5PL_PLUGIN_ENV_RELEXEC_CHAR '@' /* Maximum size for path to executable */ #ifndef MAX_EXEC_PATH @@ -128,6 +130,7 @@ typedef struct H5PL_table_t { /* Local Prototypes */ /********************/ +static char *H5PL__env_strdup(const char *plpath); static herr_t H5PL__init_path_table(void); static htri_t H5PL__find(H5PL_type_t plugin_type, int type_id, char *dir, const void **info); static htri_t H5PL__open(H5PL_type_t pl_type, char *libname, int plugin_id, const void **pl_info); @@ -182,50 +185,54 @@ DESCRIPTION herr_t H5PL__init_package(void) { - char *preload_path; - char *tempbuf; + herr_t ret_value = SUCCEED; /* Return value */ + char *preload_path = NULL; + char *tempbuf = NULL; + char pathsep = '/'; + char *bs = NULL; + size_t ncopy = MAX_EXEC_PATH; - FUNC_ENTER_PACKAGE_NOERR + FUNC_ENTER_PACKAGE /* Retrieve pathnames from HDF5_PLUGIN_PRELOAD if the user sets it * to tell the library to load plugin libraries without search. */ if(NULL != (preload_path = HDgetenv("HDF5_PLUGIN_PRELOAD"))) - /* Special symbal "::" means no plugin during data reading. */ + /* Special symbol "::" means no plugin during data reading. */ if(!HDstrcmp(preload_path, H5PL_NO_PLUGIN)) H5PL_plugin_g = 0; - /* Retrieve the executable path for use with H5PL_PLUGIN_ENV_SPECIALCHAR + /* Retrieve the executable path for use with H5PL_PLUGIN_ENV_RELEXEC_CHAR * if the user uses it in a plugin path. */ if(NULL == (tempbuf = (char *)H5MM_malloc(MAX_EXEC_PATH))) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for executable path") -#if defined(_WIN32) || defined(_WIN64) || defined(H5_HAVE_WIN32_API) - const char PathSep = '\\'; +#if defined(_WIN32) || defined(_WIN64) || defined(H5_HAVE_WIN32_API) + pathsep = (char)'\\'; GetModuleFileName(NULL, tempbuf, MAX_EXEC_PATH); #elif defined(__APPLE__) - const char PathSep = '/'; - uint32_t size = sizeof(result); - _NSGetExecutablePath(tempbuf, &size); + pathsep = (char)'/'; + { + uint32_t size = sizeof(tempbuf); + _NSGetExecutablePath(tempbuf, &size); + } #else - const char PathSep = '/'; + pathsep = (char)'/'; { ssize_t count = readlink("/proc/self/exe", tempbuf, MAX_EXEC_PATH); tempbuf[count] = '\0'; } #endif - { - char *bs = strrchr(tempbuf, PathSep); - size_t ncopy = MAX_EXEC_PATH; - if (bs) - ncopy = bs - tempbuf; - tempbuf[ncopy] = '\0'; - } + if ((bs = HDstrrchr(tempbuf, pathsep))) + ncopy = (size_t)(bs - tempbuf); + tempbuf[ncopy] = '\0'; + H5PL_executable_path_g = H5MM_strdup(tempbuf); if(tempbuf) tempbuf = (char *)H5MM_xfree(tempbuf); - FUNC_LEAVE_NOAPI(SUCCEED) +done: + FUNC_LEAVE_NOAPI(ret_value) } /* end H5PL__init_package() */ @@ -291,28 +298,33 @@ H5PL_term_package(void) } /* end H5PL_term_package() */ static char* -H5PL_env_strdup(const char *plpath) +H5PL__env_strdup(const char *plpath) { - char *dl_path = NULL; + char *ret_value = NULL; + + FUNC_ENTER_NOAPI_NOINIT + if(NULL == plpath) - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no path provided") - if (*plpath == H5PL_PLUGIN_ENV_SPECIALCHAR) { + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, NULL, "no path provided") + if (*plpath == H5PL_PLUGIN_ENV_RELEXEC_CHAR) { char *tempbuf; - int ExecPathLength = strlen(H5PL_executable_path_g); - int PluginPathLength = strlen(plpath); + size_t ExecPathLength = HDstrlen(H5PL_executable_path_g); + size_t PluginPathLength = HDstrlen(plpath); if(NULL == (tempbuf = (char *)H5MM_malloc(ExecPathLength + PluginPathLength))) - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for plugin path") + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, NULL, "can't allocate memory for plugin path") HDstrncpy(tempbuf, H5PL_executable_path_g, ExecPathLength); - HDstrncpy(tempbuf+ExecPathLength, s+1, PluginPathLength-1); + HDstrncpy(tempbuf+ExecPathLength, plpath+2, PluginPathLength-1); tempbuf[ExecPathLength + PluginPathLength] = '\0'; - dl_path = H5MM_strdup(tempbuf); + ret_value = H5MM_strdup(tempbuf); tempbuf = (char *)H5MM_xfree(tempbuf); } else - dl_path = H5MM_strdup(plpath); - return dl_path; + ret_value = H5MM_strdup(plpath); + +done: + FUNC_LEAVE_NOAPI(ret_value) } /* end H5PL_env_strdup() */ @@ -730,9 +742,9 @@ H5PLget(unsigned int index) FUNC_ENTER_API(NULL) if(H5PL_num_paths_g == 0) - HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "no directories in table") + HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, NULL, "no directories in table") if(NULL == (ret_value = H5PL_path_table_g[index])) - HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no directory path at index") + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, NULL, "no directory path at index") done: FUNC_LEAVE_API(ret_value) @@ -782,9 +794,9 @@ H5PL__init_path_table(void) */ origin_dl_path = HDgetenv("HDF5_PLUGIN_PATH"); if(NULL == origin_dl_path) - dl_path = H5MM_strdup(H5PL_DEFAULT_PATH); + dl_path = H5PL__env_strdup(H5PL_DEFAULT_PATH); else - dl_path = H5MM_strdup(origin_dl_path); + dl_path = H5PL__env_strdup(origin_dl_path); if(NULL == dl_path) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") diff --git a/test/CMakeTests.cmake b/test/CMakeTests.cmake index f372acf..959fe64 100644 --- a/test/CMakeTests.cmake +++ b/test/CMakeTests.cmake @@ -996,6 +996,12 @@ set_tests_properties (H5PLUGIN-plugin PROPERTIES WORKING_DIRECTORY ${HDF5_TEST_BINARY_DIR} ) +add_test (NAME H5PLUGIN-pluginRelative COMMAND $) +set_tests_properties (H5PLUGIN-pluginRelative PROPERTIES + ENVIRONMENT "HDF5_PLUGIN_PATH=@/../testdir1${CMAKE_SEP}@/../testdir2;srcdir=${HDF5_TEST_BINARY_DIR}" + WORKING_DIRECTORY ${HDF5_TEST_BINARY_DIR} +) + ############################################################################## ### S W M R T E S T S ############################################################################## diff --git a/test/test_plugin.sh.in b/test/test_plugin.sh.in index 1cd87e3..1e6d9d9 100644 --- a/test/test_plugin.sh.in +++ b/test/test_plugin.sh.in @@ -1,16 +1,16 @@ #! /bin/sh # -# Copyright by The HDF Group. -# All rights reserved. -# -# This file is part of HDF5. The full HDF5 copyright notice, including -# terms governing use, modification, and redistribution, is contained in -# the files COPYING and Copyright.html. COPYING can be found at the root -# of the source code distribution tree; Copyright.html can be found at the -# root level of an installed copy of the electronic document set and is -# linked from the top-level documents page. It can also be found at -# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have access -# to either file, you may request a copy from help@hdfgroup.org. +# Copyright by The HDF Group. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the files COPYING and Copyright.html. COPYING can be found at the root +# of the source code distribution tree; Copyright.html can be found at the +# root level of an installed copy of the electronic document set and is +# linked from the top-level documents page. It can also be found at +# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have access +# to either file, you may request a copy from help@hdfgroup.org. # srcdir=@srcdir@ TOP_BUILDDIR=@top_builddir@ @@ -40,7 +40,7 @@ case $(uname) in esac PLUGIN_LIBDIR1=testdir1 PLUGIN_LIBDIR2=testdir2 -CP="cp -p" # Use -p to preserve mode,ownership,timestamps +CP="cp -p" # Use -p to preserve mode,ownership,timestamps RM="rm -rf" # Print a line-line message left justified in a field of 70 characters @@ -87,6 +87,15 @@ if [ $? != 0 ]; then nerrors=`expr $nerrors + 1` fi +# setup plugin path relative to test +ENVCMD="env HDF5_PLUGIN_PATH=@/${PLUGIN_LIBDIR1}:@/${PLUGIN_LIBDIR2}" + +# Run the test +$ENVCMD $TEST_BIN +if [ $? != 0 ]; then + nerrors=`expr $nerrors + 1` +fi + # print results if test $nerrors -ne 0 ; then echo "$nerrors errors encountered" -- cgit v0.12