diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -909,6 +909,29 @@ [AC_MSG_ERROR([Cannot set default symbol visibility. Use --disable-reduce-exports.])]) fi +AC_MSG_CHECKING([for std::system]) +AC_LINK_IFELSE( + [ AC_LANG_PROGRAM( + [[ #include ]], + [[ int nErr = std::system(""); ]] + )], + [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_STD__SYSTEM, 1, Define to 1 if you have the `std::system' function.)], + [ AC_MSG_RESULT(no) ] +) + +AC_MSG_CHECKING([for ::_wsystem]) +AC_LINK_IFELSE( + [ AC_LANG_PROGRAM( + [[ ]], + [[ int nErr = ::_wsystem(""); ]] + )], + [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_WSYSTEM, 1, Define to 1 if you have the `::wsystem' function.)], + [ AC_MSG_RESULT(no) ] +) + +# Define to 1 if std::system or ::wsystem (Windows) is available +AC_DEFINE([HAVE_SYSTEM], [HAVE_STD__SYSTEM || HAVE_WSYSTEM], [std::system or ::wsystem]) + LEVELDB_CPPFLAGS= LIBLEVELDB= LIBMEMENV= diff --git a/src/config/CMakeLists.txt b/src/config/CMakeLists.txt --- a/src/config/CMakeLists.txt +++ b/src/config/CMakeLists.txt @@ -5,6 +5,7 @@ include(CheckIncludeFiles) include(CheckSymbolExists) +include(CheckCXXSymbolExists) include(CheckCXXSourceCompiles) # Version @@ -217,5 +218,12 @@ set(USE_DBUS 1) endif() +# Check if std::system or ::wsystem is available +check_cxx_symbol_exists(std::system "cstdlib" _HAVE_STD_SYSTEM) +check_cxx_symbol_exists(::wsystem "" _HAVE_WSYSTEM) +if(_HAVE_STD_SYSTEM OR _HAVE_WSYSTEM) + set(HAVE_SYSTEM 1) +endif() + # Generate the config configure_file(bitcoin-config.h.cmake.in bitcoin-config.h ESCAPE_QUOTES) diff --git a/src/config/bitcoin-config.h.cmake.in b/src/config/bitcoin-config.h.cmake.in --- a/src/config/bitcoin-config.h.cmake.in +++ b/src/config/bitcoin-config.h.cmake.in @@ -60,6 +60,8 @@ #cmakedefine HAVE_SYSCTL_ARND 1 +#cmakedefine HAVE_SYSTEM 1 + #cmakedefine CHAR_EQUALS_INT8 0 #cmakedefine HAVE_LARGE_FILE_SUPPORT 1 diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -373,10 +373,12 @@ ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); gArgs.AddArg("-version", "Print version and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); +#if defined(HAVE_SYSTEM) gArgs.AddArg("-alertnotify=", "Execute command when a relevant alert is received or we see " "a really long fork (%s in cmd is replaced by message)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); +#endif gArgs.AddArg( "-assumevalid=", strprintf( @@ -390,10 +392,12 @@ "Specify directory to hold blocks subdirectory for *.dat " "files (default: )", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); +#if defined(HAVE_SYSTEM) gArgs.AddArg("-blocknotify=", "Execute command when the best block changes (%s in cmd is " "replaced by block hash)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); +#endif gArgs.AddArg("-blockreconstructionextratxn=", strprintf("Extra transactions to keep in memory for compact " "block reconstructions (default: %u)", @@ -1172,6 +1176,7 @@ "\n"; } +#if defined(HAVE_SYSTEM) static void BlockNotifyCallback(bool initialSync, const CBlockIndex *pBlockIndex) { if (initialSync || !pBlockIndex) { @@ -1186,6 +1191,7 @@ t.detach(); } } +#endif static bool fHaveGenesis = false; static Mutex g_genesis_wait_mutex; @@ -2655,9 +2661,11 @@ fHaveGenesis = true; } +#if defined(HAVE_SYSTEM) if (gArgs.IsArgSet("-blocknotify")) { uiInterface.NotifyBlockTip_connect(BlockNotifyCallback); } +#endif std::vector vImportFiles; for (const std::string &strFile : gArgs.GetArgs("-loadblock")) { diff --git a/src/util/system.h b/src/util/system.h --- a/src/util/system.h +++ b/src/util/system.h @@ -82,7 +82,9 @@ #ifdef WIN32 fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true); #endif +#if defined(HAVE_SYSTEM) void runCommand(const std::string &strCommand); +#endif NODISCARD bool ParseKeyValue(std::string &key, std::string &val); diff --git a/src/util/system.cpp b/src/util/system.cpp --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -1167,6 +1167,7 @@ } #endif +#if defined(HAVE_SYSTEM) void runCommand(const std::string &strCommand) { if (strCommand.empty()) { return; @@ -1184,6 +1185,7 @@ nErr); } } +#endif void SetupEnvironment() { #ifdef HAVE_MALLOPT_ARENA_MAX diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -825,6 +825,7 @@ static void AlertNotify(const std::string &strMessage) { uiInterface.NotifyAlertChanged(); +#if defined(HAVE_SYSTEM) std::string strCmd = gArgs.GetArg("-alertnotify", ""); if (strCmd.empty()) { return; @@ -841,6 +842,7 @@ std::thread t(runCommand, strCmd); // thread runs free t.detach(); +#endif } static void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main) { diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -114,10 +114,12 @@ "Specify directory to hold wallets (default: " "/wallets if it exists, otherwise )", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET); +#if defined(HAVE_SYSTEM) gArgs.AddArg("-walletnotify=", "Execute command when a wallet transaction changes (%s in cmd " "is replaced by TxID)", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET); +#endif gArgs.AddArg( "-zapwallettxes=", "Delete all wallet transactions and only recover those parts of the " diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1222,6 +1222,7 @@ // Notify UI of new or updated transaction. NotifyTransactionChanged(this, txid, fInsertedNew ? CT_NEW : CT_UPDATED); +#if defined(HAVE_SYSTEM) // Notify an external script when a wallet transaction comes in or is // updated. std::string strCmd = gArgs.GetArg("-walletnotify", ""); @@ -1232,6 +1233,7 @@ // Thread runs free. t.detach(); } +#endif return true; }