Skip to content

Commit 8c69fae

Browse files
committed
Merge #15457: Check std::system for -[alert|block|wallet]notify
f874e14 [build]: check std::system for -[alert|block|wallet]notify (Sjors Provoost) cc3ad56 [build] MSVC: set HAVE_SYSTEM for desktop apps (Sjors Provoost) c1c91bb [build] detect std::system or ::wsystem (Sjors Provoost) Pull request description: Platforms such as iOs and Universal Windows Platform do not support launching a process through system(). ACKs for top commit: laanwj: code review ACK f874e14 Tree-SHA512: 16bb4a8fa1896046ccb22a46c8985e1aa45f5b11ecf5539eb2299e9a58f1a5b085c0c12cb6939c7493d93abce7e84fadcbfc73374c887db63da6d00c08aa476d
2 parents 4f378ac + f874e14 commit 8c69fae

File tree

8 files changed

+51
-0
lines changed

8 files changed

+51
-0
lines changed

build_msvc/bitcoin_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,14 @@
421421
/* Define for large files, on AIX-style hosts. */
422422
/* #undef _LARGE_FILES */
423423

424+
/* Windows Universal Platform constraints */
425+
#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
426+
/* Either a desktop application without API restrictions, or and older system
427+
before these macros were defined. */
428+
429+
/* ::wsystem is available */
430+
#define HAVE_SYSTEM 1
431+
432+
#endif // !WINAPI_FAMILY || WINAPI_FAMILY_DESKTOP_APP
433+
424434
#endif //BITCOIN_BITCOIN_CONFIG_H

configure.ac

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,29 @@ if test x$use_reduce_exports = xyes; then
925925
[AC_MSG_ERROR([Cannot set default symbol visibility. Use --disable-reduce-exports.])])
926926
fi
927927

928+
AC_MSG_CHECKING([for std::system])
929+
AC_LINK_IFELSE(
930+
[ AC_LANG_PROGRAM(
931+
[[ #include <cstdlib> ]],
932+
[[ int nErr = std::system(""); ]]
933+
)],
934+
[ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_STD__SYSTEM, 1, Define to 1 if you have the `std::system' function.)],
935+
[ AC_MSG_RESULT(no) ]
936+
)
937+
938+
AC_MSG_CHECKING([for ::_wsystem])
939+
AC_LINK_IFELSE(
940+
[ AC_LANG_PROGRAM(
941+
[[ ]],
942+
[[ int nErr = ::_wsystem(""); ]]
943+
)],
944+
[ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_WSYSTEM, 1, Define to 1 if you have the `::wsystem' function.)],
945+
[ AC_MSG_RESULT(no) ]
946+
)
947+
948+
# Define to 1 if std::system or ::wsystem (Windows) is available
949+
AC_DEFINE([HAVE_SYSTEM], [HAVE_STD__SYSTEM || HAVE_WSYSTEM], [std::system or ::wsystem])
950+
928951
LEVELDB_CPPFLAGS=
929952
LIBLEVELDB=
930953
LIBMEMENV=

src/init.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,14 @@ void SetupServerArgs()
376376
"-allowselfsignedrootcertificates", "-choosedatadir", "-lang=<lang>", "-min", "-resetguisettings", "-rootcertificates=<file>", "-splash", "-uiplatform"};
377377

378378
gArgs.AddArg("-version", "Print version and exit", false, OptionsCategory::OPTIONS);
379+
#if defined(HAVE_SYSTEM)
379380
gArgs.AddArg("-alertnotify=<cmd>", "Execute command when a relevant alert is received or we see a really long fork (%s in cmd is replaced by message)", false, OptionsCategory::OPTIONS);
381+
#endif
380382
gArgs.AddArg("-assumevalid=<hex>", strprintf("If this block is in the chain assume that it and its ancestors are valid and potentially skip their script verification (0 to verify all, default: %s, testnet: %s)", defaultChainParams->GetConsensus().defaultAssumeValid.GetHex(), testnetChainParams->GetConsensus().defaultAssumeValid.GetHex()), false, OptionsCategory::OPTIONS);
381383
gArgs.AddArg("-blocksdir=<dir>", "Specify directory to hold blocks subdirectory for *.dat files (default: <datadir>)", false, OptionsCategory::OPTIONS);
384+
#if defined(HAVE_SYSTEM)
382385
gArgs.AddArg("-blocknotify=<cmd>", "Execute command when the best block changes (%s in cmd is replaced by block hash)", false, OptionsCategory::OPTIONS);
386+
#endif
383387
gArgs.AddArg("-blockreconstructionextratxn=<n>", strprintf("Extra transactions to keep in memory for compact block reconstructions (default: %u)", DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN), false, OptionsCategory::OPTIONS);
384388
gArgs.AddArg("-blocksonly", strprintf("Whether to reject transactions from network peers. Transactions from the wallet or RPC are not affected. (default: %u)", DEFAULT_BLOCKSONLY), false, OptionsCategory::OPTIONS);
385389
gArgs.AddArg("-conf=<file>", strprintf("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME), false, OptionsCategory::OPTIONS);
@@ -579,6 +583,7 @@ std::string LicenseInfo()
579583
"\n";
580584
}
581585

586+
#if defined(HAVE_SYSTEM)
582587
static void BlockNotifyCallback(bool initialSync, const CBlockIndex *pBlockIndex)
583588
{
584589
if (initialSync || !pBlockIndex)
@@ -591,6 +596,7 @@ static void BlockNotifyCallback(bool initialSync, const CBlockIndex *pBlockIndex
591596
t.detach(); // thread runs free
592597
}
593598
}
599+
#endif
594600

595601
static bool fHaveGenesis = false;
596602
static Mutex g_genesis_wait_mutex;
@@ -1708,8 +1714,10 @@ bool AppInitMain(InitInterfaces& interfaces)
17081714
fHaveGenesis = true;
17091715
}
17101716

1717+
#if defined(HAVE_SYSTEM)
17111718
if (gArgs.IsArgSet("-blocknotify"))
17121719
uiInterface.NotifyBlockTip_connect(BlockNotifyCallback);
1720+
#endif
17131721

17141722
std::vector<fs::path> vImportFiles;
17151723
for (const std::string& strFile : gArgs.GetArgs("-loadblock")) {

src/util/system.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,7 @@ fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
11141114
}
11151115
#endif
11161116

1117+
#if defined(HAVE_SYSTEM)
11171118
void runCommand(const std::string& strCommand)
11181119
{
11191120
if (strCommand.empty()) return;
@@ -1125,6 +1126,7 @@ void runCommand(const std::string& strCommand)
11251126
if (nErr)
11261127
LogPrintf("runCommand error: system(%s) returned %d\n", strCommand, nErr);
11271128
}
1129+
#endif
11281130

11291131
void SetupEnvironment()
11301132
{

src/util/system.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ fs::path GetConfigFile(const std::string& confPath);
8989
#ifdef WIN32
9090
fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
9191
#endif
92+
#if defined(HAVE_SYSTEM)
9293
void runCommand(const std::string& strCommand);
94+
#endif
9395

9496
/**
9597
* Most paths passed as configuration arguments are treated as relative to

src/validation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,7 @@ static CBlockIndex *pindexBestForkTip = nullptr, *pindexBestForkBase = nullptr;
10501050
static void AlertNotify(const std::string& strMessage)
10511051
{
10521052
uiInterface.NotifyAlertChanged();
1053+
#if defined(HAVE_SYSTEM)
10531054
std::string strCmd = gArgs.GetArg("-alertnotify", "");
10541055
if (strCmd.empty()) return;
10551056

@@ -1063,6 +1064,7 @@ static void AlertNotify(const std::string& strMessage)
10631064

10641065
std::thread t(runCommand, strCmd);
10651066
t.detach(); // thread runs free
1067+
#endif
10661068
}
10671069

10681070
static void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main)

src/wallet/init.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ void WalletInit::AddWalletOptions() const
5757
gArgs.AddArg("-wallet=<path>", "Specify wallet database path. Can be specified multiple times to load multiple wallets. Path is interpreted relative to <walletdir> if it is not absolute, and will be created if it does not exist (as a directory containing a wallet.dat file and log files). For backwards compatibility this will also accept names of existing data files in <walletdir>.)", false, OptionsCategory::WALLET);
5858
gArgs.AddArg("-walletbroadcast", strprintf("Make the wallet broadcast transactions (default: %u)", DEFAULT_WALLETBROADCAST), false, OptionsCategory::WALLET);
5959
gArgs.AddArg("-walletdir=<dir>", "Specify directory to hold wallets (default: <datadir>/wallets if it exists, otherwise <datadir>)", false, OptionsCategory::WALLET);
60+
#if defined(HAVE_SYSTEM)
6061
gArgs.AddArg("-walletnotify=<cmd>", "Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)", false, OptionsCategory::WALLET);
62+
#endif
6163
gArgs.AddArg("-walletrbf", strprintf("Send transactions with full-RBF opt-in enabled (RPC only, default: %u)", DEFAULT_WALLET_RBF), false, OptionsCategory::WALLET);
6264
gArgs.AddArg("-zapwallettxes=<mode>", "Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup"
6365
" (1 = keep tx meta data e.g. payment request information, 2 = drop tx meta data)", false, OptionsCategory::WALLET);

src/wallet/wallet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
10501050
// Notify UI of new or updated transaction
10511051
NotifyTransactionChanged(this, hash, fInsertedNew ? CT_NEW : CT_UPDATED);
10521052

1053+
#if defined(HAVE_SYSTEM)
10531054
// notify an external script when a wallet transaction comes in or is updated
10541055
std::string strCmd = gArgs.GetArg("-walletnotify", "");
10551056

@@ -1059,6 +1060,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
10591060
std::thread t(runCommand, strCmd);
10601061
t.detach(); // thread runs free
10611062
}
1063+
#endif
10621064

10631065
return true;
10641066
}

0 commit comments

Comments
 (0)