Skip to content

Commit f874e14

Browse files
committed
[build]: check std::system for -[alert|block|wallet]notify
Platforms such as iOs do not support launching a process through system().
1 parent cc3ad56 commit f874e14

File tree

7 files changed

+19
-1
lines changed

7 files changed

+19
-1
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ AC_LINK_IFELSE(
946946
)
947947

948948
# Define to 1 if std::system or ::wsystem (Windows) is available
949-
AC_DEFINE([HAVE_SYSTEM], [HAVE_STD__SYSTEM || HAVE_WSYSTEM], [HAVE_WSYSTEM])
949+
AC_DEFINE([HAVE_SYSTEM], [HAVE_STD__SYSTEM || HAVE_WSYSTEM], [std::system or ::wsystem])
950950

951951
LEVELDB_CPPFLAGS=
952952
LIBLEVELDB=

src/init.cpp

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

380380
gArgs.AddArg("-version", "Print version and exit", false, OptionsCategory::OPTIONS);
381+
#if defined(HAVE_SYSTEM)
381382
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);
383+
#endif
382384
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);
383385
gArgs.AddArg("-blocksdir=<dir>", "Specify directory to hold blocks subdirectory for *.dat files (default: <datadir>)", false, OptionsCategory::OPTIONS);
386+
#if defined(HAVE_SYSTEM)
384387
gArgs.AddArg("-blocknotify=<cmd>", "Execute command when the best block changes (%s in cmd is replaced by block hash)", false, OptionsCategory::OPTIONS);
388+
#endif
385389
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);
386390
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);
387391
gArgs.AddArg("-conf=<file>", strprintf("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME), false, OptionsCategory::OPTIONS);
@@ -582,6 +586,7 @@ std::string LicenseInfo()
582586
"\n";
583587
}
584588

589+
#if defined(HAVE_SYSTEM)
585590
static void BlockNotifyCallback(bool initialSync, const CBlockIndex *pBlockIndex)
586591
{
587592
if (initialSync || !pBlockIndex)
@@ -594,6 +599,7 @@ static void BlockNotifyCallback(bool initialSync, const CBlockIndex *pBlockIndex
594599
t.detach(); // thread runs free
595600
}
596601
}
602+
#endif
597603

598604
static bool fHaveGenesis = false;
599605
static Mutex g_genesis_wait_mutex;
@@ -1726,8 +1732,10 @@ bool AppInitMain(InitInterfaces& interfaces)
17261732
fHaveGenesis = true;
17271733
}
17281734

1735+
#if defined(HAVE_SYSTEM)
17291736
if (gArgs.IsArgSet("-blocknotify"))
17301737
uiInterface.NotifyBlockTip_connect(BlockNotifyCallback);
1738+
#endif
17311739

17321740
std::vector<fs::path> vImportFiles;
17331741
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
@@ -1122,6 +1122,7 @@ fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
11221122
}
11231123
#endif
11241124

1125+
#if defined(HAVE_SYSTEM)
11251126
void runCommand(const std::string& strCommand)
11261127
{
11271128
if (strCommand.empty()) return;
@@ -1133,6 +1134,7 @@ void runCommand(const std::string& strCommand)
11331134
if (nErr)
11341135
LogPrintf("runCommand error: system(%s) returned %d\n", strCommand, nErr);
11351136
}
1137+
#endif
11361138

11371139
void SetupEnvironment()
11381140
{

src/util/system.h

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

9597
/**
9698
* 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
@@ -1054,6 +1054,7 @@ CBlockIndex *pindexBestForkTip = nullptr, *pindexBestForkBase = nullptr;
10541054
static void AlertNotify(const std::string& strMessage)
10551055
{
10561056
uiInterface.NotifyAlertChanged();
1057+
#if defined(HAVE_SYSTEM)
10571058
std::string strCmd = gArgs.GetArg("-alertnotify", "");
10581059
if (strCmd.empty()) return;
10591060

@@ -1067,6 +1068,7 @@ static void AlertNotify(const std::string& strMessage)
10671068

10681069
std::thread t(runCommand, strCmd);
10691070
t.detach(); // thread runs free
1071+
#endif
10701072
}
10711073

10721074
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
@@ -62,7 +62,9 @@ void WalletInit::AddWalletOptions() const
6262
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);
6363
gArgs.AddArg("-walletbroadcast", strprintf("Make the wallet broadcast transactions (default: %u)", DEFAULT_WALLETBROADCAST), false, OptionsCategory::WALLET);
6464
gArgs.AddArg("-walletdir=<dir>", "Specify directory to hold wallets (default: <datadir>/wallets if it exists, otherwise <datadir>)", false, OptionsCategory::WALLET);
65+
#if defined(HAVE_SYSTEM)
6566
gArgs.AddArg("-walletnotify=<cmd>", "Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)", false, OptionsCategory::WALLET);
67+
#endif
6668
gArgs.AddArg("-walletrbf", strprintf("Send transactions with full-RBF opt-in enabled (RPC only, default: %u)", DEFAULT_WALLET_RBF), false, OptionsCategory::WALLET);
6769
gArgs.AddArg("-zapwallettxes=<mode>", "Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup"
6870
" (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
@@ -1008,6 +1008,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
10081008
// Notify UI of new or updated transaction
10091009
NotifyTransactionChanged(this, hash, fInsertedNew ? CT_NEW : CT_UPDATED);
10101010

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

@@ -1017,6 +1018,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
10171018
std::thread t(runCommand, strCmd);
10181019
t.detach(); // thread runs free
10191020
}
1021+
#endif
10201022

10211023
return true;
10221024
}

0 commit comments

Comments
 (0)