From f8017d1685b0aac61251b5a0f27cd4336100d2f9 Mon Sep 17 00:00:00 2001 From: Eric Berquist Date: Wed, 6 Sep 2023 21:57:32 -0400 Subject: [PATCH] Fix filesystem operations when unregistering elements (#983) * use std::filesystem::rename * remove unused autoconf scripts for past C++ standards * update autoconf C++ standard flag checkers * Fix file operations for unregistering components * Switch from filesystem library to cstdio * Use an autogenerated temporary file name --- config/ax_cxx_compile_stdcxx.m4 | 20 ++++- config/ax_cxx_compile_stdcxx_04.m4 | 117 ----------------------------- config/ax_cxx_compile_stdcxx_14.m4 | 95 ----------------------- config/ax_cxx_compile_stdcxx_17.m4 | 62 +++++++-------- src/sst/core/sstregistertool.cc | 27 ++++--- 5 files changed, 65 insertions(+), 256 deletions(-) delete mode 100644 config/ax_cxx_compile_stdcxx_04.m4 delete mode 100644 config/ax_cxx_compile_stdcxx_14.m4 diff --git a/config/ax_cxx_compile_stdcxx.m4 b/config/ax_cxx_compile_stdcxx.m4 index e9d093242..9ba371396 100644 --- a/config/ax_cxx_compile_stdcxx.m4 +++ b/config/ax_cxx_compile_stdcxx.m4 @@ -43,7 +43,7 @@ # and this notice are preserved. This file is offered as-is, without any # warranty. -#serial 15 +#serial 18 dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro dnl (serial version number 13). @@ -104,9 +104,18 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl dnl HP's aCC needs +std=c++11 according to: dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf dnl Cray's crayCC needs "-h std=c++11" + dnl MSVC needs -std:c++NN for C++17 and later (default is C++14) for alternative in ${ax_cxx_compile_alternatives}; do - for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do - cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}" MSVC; do + if test x"$switch" = xMSVC; then + dnl AS_TR_SH maps both `:` and `=` to `_` so -std:c++17 would collide + dnl with -std=c++17. We suffix the cache variable name with _MSVC to + dnl avoid this. + switch=-std:c++${alternative} + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_${switch}_MSVC]) + else + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + fi AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, $cachevar, [ac_save_CXX="$CXX" @@ -116,6 +125,10 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl [eval $cachevar=no]) CXX="$ac_save_CXX"]) if eval test x\$$cachevar = xyes; then + CXX="$CXX $switch" + if test -n "$CXXCPP" ; then + CXXCPP="$CXXCPP $switch" + fi ac_success=yes break fi @@ -1003,4 +1016,3 @@ namespace cxx20 #endif // __cplusplus < 202002L && !defined _MSC_VER ]]) - diff --git a/config/ax_cxx_compile_stdcxx_04.m4 b/config/ax_cxx_compile_stdcxx_04.m4 deleted file mode 100644 index 37a205d04..000000000 --- a/config/ax_cxx_compile_stdcxx_04.m4 +++ /dev/null @@ -1,117 +0,0 @@ -# ============================================================================ -# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_0x.html -# ============================================================================ -# -# SYNOPSIS -# -# AX_CXX_COMPILE_STDCXX_0X -# -# DESCRIPTION -# -# Check for baseline language coverage in the compiler for the C++0x -# standard. -# -# LICENSE -# -# Copyright (c) 2008 Benjamin Kosnik -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. This file is offered as-is, without any -# warranty. - -#serial 7 - -AU_ALIAS([AC_CXX_COMPILE_STDCXX_0X], [AX_CXX_COMPILE_STDCXX_0X]) - -AC_DEFUN([AX_CXX_COMPILE_STDCXX_0X], [ - SST_CXX0X_FLAGS="" - - AC_CACHE_CHECK(if C++ supports C++0x features without additional flags, - ax_cv_cxx_compile_cxx0x_native, - [AC_LANG_PUSH([C++]) - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = static_cast(c);]], [])], - [ax_cv_cxx_compile_cxx0x_native=yes], [ax_cv_cxx_compile_cxx0x_native=no]) - AC_LANG_POP([C++]) - ]) - - SST_CXX0X_FLAGS="" - - AC_CACHE_CHECK(if C++ supports C++0x features with -std=c++11, - ax_cv_cxx_compile_cxx11_cxx, - [AC_LANG_PUSH([C++]) - ac_save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS -std=c++11 -D__STDC_FORMAT_MACROS" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = static_cast(c);]], [])], - [ax_cv_cxx_compile_cxx11_cxx=yes], [ax_cv_cxx_compile_cxx11_cxx=no]) - CXXFLAGS=$ac_save_CXXFLAGS - AS_IF([test "$ax_cv_cxx_compile_cxx11_cxx" = "yes" ], [SST_CXX0X_FLAGS="-std=c++11 -D__STDC_FORMAT_MACROS"]) - - AC_LANG_POP([C++]) - ]) - - AS_IF([test "$ax_cv_cxx_compile_cxx11_cxx" != "yes"], [ - - AC_CACHE_CHECK(if C++ supports C++0x features with -std=c++0x, - ax_cv_cxx_compile_cxx0x_cxx, - [AC_LANG_PUSH([C++]) - ac_save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS -std=c++0x -D__STDC_FORMAT_MACROS" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = static_cast(c);]], [])], - [ax_cv_cxx_compile_cxx0x_cxx=yes], [ax_cv_cxx_compile_cxx0x_cxx=no]) - CXXFLAGS=$ac_save_CXXFLAGS - AS_IF([test "$ax_cv_cxx_compile_cxx0x_cxx" = "yes" ], [SST_CXX0X_FLAGS="-std=c++0x -D__STDC_FORMAT_MACROS"]) - AC_LANG_POP([C++]) - - ]) - ]) - - AS_IF( [test "$ax_cv_cxx_compile_cxx0x_native" = "yes" -o "$ax_cv_cxx_compile_cxx0x_cxx" = "yes" -o "$ax_cv_cxx_compile_cxx11_cxx" = "yes" ], - [found_cxx0x="yes"], [found_cxx0x="no"] ) - - AS_IF( [test "x$found_cxx1y" = "xno" -a "x$found_cxx0x" = "xno"], - [AC_MSG_ERROR([Could not found C++14 or C++11 support but this is required for SST to successfully build.], [1]) ]) - AC_SUBST([SST_CXX0X_FLAGS]) -]) diff --git a/config/ax_cxx_compile_stdcxx_14.m4 b/config/ax_cxx_compile_stdcxx_14.m4 deleted file mode 100644 index 523829d7a..000000000 --- a/config/ax_cxx_compile_stdcxx_14.m4 +++ /dev/null @@ -1,95 +0,0 @@ - -AU_ALIAS([AC_CXX_COMPILE_STDCXX_1Y], [AX_CXX_COMPILE_STDCXX_1Y]) - -AC_DEFUN([AX_CXX_COMPILE_STDCXX_1Y], [ - SST_CXX1Y_FLAGS="" - - AC_CACHE_CHECK(if C++ supports C++1y features without additional flags, - ax_cv_cxx_compile_cxx1y_native, - [AC_LANG_PUSH([C++]) - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = static_cast(c);]], [])], - [ax_cv_cxx_compile_cxx1y_native=yes], [ax_cv_cxx_compile_cxx1y_native=no]) - AC_LANG_POP([C++]) - ]) - - SST_CXX1Y_FLAGS="" - - AC_CACHE_CHECK(if C++ supports C++1y features with -std=c++14, - ax_cv_cxx_compile_cxx14_cxx, - [AC_LANG_PUSH([C++]) - ac_save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS -std=c++14 -D__STDC_FORMAT_MACROS" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = static_cast(c);]]), [])], - [ax_cv_cxx_compile_cxx_14_cxx=yes], [ax_cv_cxx_compile_cxx_14_cxx=no]) - CXXFLAGS=$ac_save_CXXFLAGS - AS_IF([test "$ax_cv_cxx_compile_cxx_14_cxx" = "yes" ], [SST_CXX1Y_FLAGS="-std=c++14 -D__STDC_FORMAT_MACROS"]) - - AC_LANG_POP([C++]) - ]) - - AS_IF([test "$ax_cv_cxx_compile_cxx14_cxx" != "yes"], [ - - AC_CACHE_CHECK(if C++ supports C++1y features with -std=c++1y, - ax_cv_cxx_compile_cxx1y_cxx, - [AC_LANG_PUSH([C++]) - ac_save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS -std=c++1y -D__STDC_FORMAT_MACROS" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = static_cast(c);]], [])], - [ax_cv_cxx_compile_cxx1y_cxx=yes], [ax_cv_cxx_compile_cxx1y_cxx=no]) - CXXFLAGS=$ac_save_CXXFLAGS - AS_IF([test "$ax_cv_cxx_compile_cxx1y_cxx" = "yes" ], [SST_CXX1Y_FLAGS="-std=c++1y -D__STDC_FORMAT_MACROS"]) - AC_LANG_POP([C++]) - - ]) - ]) - - AS_IF( [test "$ax_cv_cxx_compile_cxx1y_native" = "yes" -o "$ax_cv_cxx_compile_cxx1y_cxx" = "yes" -o "$ax_cv_cxx_compile_cxx14_cxx" = "yes" ], - [found_cxx1y="yes"], [found_cxx1y="no"] ) - - AC_DEFINE(HAVE_STDCXX_1Y, [1], [Define if C++ supports C++14 features.]) - AC_SUBST([SST_CXX1Y_FLAGS]) - AM_CONDITIONAL([HAVE_STDCXX_1Y], [test "x$found_cxx1y" = "xyes"]) -]) - diff --git a/config/ax_cxx_compile_stdcxx_17.m4 b/config/ax_cxx_compile_stdcxx_17.m4 index c141a0fa2..a68341717 100644 --- a/config/ax_cxx_compile_stdcxx_17.m4 +++ b/config/ax_cxx_compile_stdcxx_17.m4 @@ -1,35 +1,35 @@ # ============================================================================= -# Elements://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_17.html +# https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_17.html # ============================================================================= -# # -# # SYNOPSIS -# # -# # AX_CXX_COMPILE_STDCXX_17([ext|noext], [mandatory|optional]) -# # -# # DESCRIPTION -# # -# # Check for baseline language coverage in the compiler for the C++17 -# # standard; if necessary, add switches to CXX and CXXCPP to enable -# # support. -# # -# # This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX -# # macro with the version set to C++17. The two optional arguments are -# # forwarded literally as the second and third argument respectively. -# # Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for -# # more information. If you want to use this macro, you also need to -# # download the ax_cxx_compile_stdcxx.m4 file. -# # -# # LICENSE -# # -# # Copyright (c) 2015 Moritz Klammler -# # Copyright (c) 2016 Krzesimir Nowak -# # -# # Copying and distribution of this file, with or without modification, are -# # permitted in any medium without royalty provided the copyright notice -# # and this notice are preserved. This file is offered as-is, without any -# # warranty. -# -# #serial 2 # +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX_17([ext|noext], [mandatory|optional]) +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the C++17 +# standard; if necessary, add switches to CXX and CXXCPP to enable +# support. +# +# This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX +# macro with the version set to C++17. The two optional arguments are +# forwarded literally as the second and third argument respectively. +# Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for +# more information. If you want to use this macro, you also need to +# download the ax_cxx_compile_stdcxx.m4 file. +# +# LICENSE +# +# Copyright (c) 2015 Moritz Klammler +# Copyright (c) 2016 Krzesimir Nowak +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 2 + AX_REQUIRE_DEFINED([AX_CXX_COMPILE_STDCXX]) -AC_DEFUN([AX_CXX_COMPILE_STDCXX_17], [AX_CXX_COMPILE_STDCXX([17], [$1], [$2])]) +AC_DEFUN([AX_CXX_COMPILE_STDCXX_17], [AX_CXX_COMPILE_STDCXX([17], [$1], [$2])]) diff --git a/src/sst/core/sstregistertool.cc b/src/sst/core/sstregistertool.cc index d926fdf3d..1a9fa97b2 100644 --- a/src/sst/core/sstregistertool.cc +++ b/src/sst/core/sstregistertool.cc @@ -148,14 +148,12 @@ sstRegister(char* argv[]) void sstUnregister(const std::string& element) { - std::string str1; - std::string s = ""; - std::string tempfile; - int found = 0; - // setup element names to look for - str1 = START_DELIMITER + element + STOP_DELIMITER; - tempfile = "/tmp/sstsimulator.conf"; + const std::string str1 = START_DELIMITER + element + STOP_DELIMITER; + const auto tempfile = std::tmpnam(nullptr); + + std::string s = ""; + int found = 0; std::ifstream infile(cfgPath); std::ofstream outfile(tempfile); @@ -174,11 +172,22 @@ sstUnregister(const std::string& element) if ( found ) { std::cout << "\tModel " << element << " has been unregistered!\n"; } else - std::cout << "Model " << element << " not found\n\n"; + std::cout << "\tModel " << element << " not found\n\n"; infile.close(); outfile.close(); - rename(tempfile.c_str(), cfgPath); + + if ( std::remove(cfgPath) != 0 ) { + std::cerr << "\tError removing " << cfgPath << " before moving updated config\n"; + return; + } + infile = std::ifstream(tempfile, std::ios::binary); + outfile = std::ofstream(cfgPath, std::ios::binary); + outfile << infile.rdbuf(); + if ( std::remove(tempfile) != 0 ) { + std::cerr << "\tError removing " << tempfile << " after moving updated config\n"; + return; + } } // listModels