Check that -blocknotify command is non-empty before executing.
To make the BlockNotifyCallback(...) (-blocknotify) behaviour consistent with that of:
AlertNotify(...)(-alertnotify)AddToWallet(...)(-walletnotify)
Check that -blocknotify command is non-empty before executing.
To make the BlockNotifyCallback(...) (-blocknotify) behaviour consistent with that of:
AlertNotify(...) (-alertnotify)AddToWallet(...) (-walletnotify)939 | @@ -940,7 +940,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose) 940 | // notify an external script when a wallet transaction comes in or is updated 941 | std::string strCmd = GetArg("-walletnotify", ""); 942 | 943 | - if ( !strCmd.empty()) 944 | + if (!strCmd.empty())
Unrelated.
That change was intentional to show how the logic is handled in AddToWallet (-walletnotify).
544 | @@ -545,9 +545,10 @@ static void BlockNotifyCallback(bool initialSync, const CBlockIndex *pBlockIndex 545 | return; 546 | 547 | std::string strCmd = GetArg("-blocknotify", ""); 548 | - 549 | - boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex()); 550 | - boost::thread t(runCommand, strCmd); // thread runs free 551 | + if (!strCmd.empty()) {
No need to test because in init.cpp there's:
if (IsArgSet("-blocknotify"))
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback);
Does IsArgSet(…) test for emptiness?
Ignore if you want to keep the test here.
Partial ACK. IMO the check should be in init.cpp:
if (!GetArg("-blocknotify", "").empty()) {
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback);
}
That way it's checked one time only.
@promag I prefer doing a check inside of BlockNotifyCallback(…) (as close as possible to the RunCommand(…)) since:
BlockNotifyCallback(…) might be invoked from other places in the future.AlertNotify(...) (-alertnotify) and AddToWallet(...) (-walletnotify).Side note, should we treat empty args as invalid?
@promag In the specific case of -{alert,block,wallet}notify: yes - no need to execute "" :-)
Side note, should we treat empty args as invalid?
Depends on the specific argument. For some things, an empty string might be a valid value, for others it's not.
For executing a command it makes sense to skip it when the string is empty.
What does system("") do? spawn a shell?
BTW: Why not handle this in runCommand? that seems the shortest path to making this consistent.
What does system("") do? spawn a shell?
It already does nothing! Same for system(" "); etc.
Why do we need this change?
Not convinced that "custom logging" makes sense here. The user provided an empty command, which non-ambiguously means they don't want it to do anything. It doesn't do anything.
(maybe skipping could be considered a small optimization, but could leave it up to the user to just not provide the argument at all so that the signal doesn't get registered? I have a hard time imagining any circumstance where this would matter at all)
@laanwj My original idea was to make -blocknotify, -alertnotify and -walletnotify behave identically with regards to thread creation and execve(…)-calls in case of an "" argument. Not a big issue, just a small step towards increased user interface consistency :-)
@laanwj IMO empty commands should be invalid. The same goes for when a command does not exists. Not providing the argument/command should be the correct way to run nothing.
For instance, with find it fails:
$ find . -exec \;
find: -exec: no command specified
To make BlockNotifyCallback(...) (-blocknotify) consistent with:
* AlertNotify(...) (-alertnotify)
* AddToWallet(...) (-walletnotify)
(slightly offtopic) @promag - I'm with you on this one. I'd like there to be better systematic validation of command line-arguments.
I think you've spoken about argument validation on a few issues. Perhaps we should raise this in a future meeting to get concept feedback?
utACK
We shouldn't make the empty command invalid so quickly: if one has blocknotify=foobar in the bitcoin.conf file, they may wish to use -blocknotify= on the commandline to temporarily disable it.
(The alternative, -noblocknotify, is probably broken...)
they may wish to use -blocknotify=
They can remove the line or comment it out?
Better if no change to the config file is needed for such a temporary purpose.
@luke-jr raises a good point. Being able to override and temporarily disable .conf file options from the command line is very useful. This PR allows that (supplying blocknotify= won't cause an error).
Has anyone tested what happens with noblocknotify?
We shouldn't make the empty command invalid so quickly: if one has blocknotify=foobar in the bitcoin.conf file, they may wish to use -blocknotify= on the commandline to temporarily disable it.
Good point! And the first good argument for doing this at all. Being able to overriding the blocknotify command with "" (say, from the command line) to disable it is useful. In that case you don't want an empty command to be executed as that just wastes resources.
utACK cffe85f