New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[init] Check non-emptiness of -blocknotify command prior to executing #10939
[init] Check non-emptiness of -blocknotify command prior to executing #10939
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
src/wallet/wallet.cpp
Outdated
@@ -940,7 +940,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose) | |||
// notify an external script when a wallet transaction comes in or is updated | |||
std::string strCmd = GetArg("-walletnotify", ""); | |||
|
|||
if ( !strCmd.empty()) | |||
if (!strCmd.empty()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That change was intentional to show how the logic is handled in AddToWallet
(-walletnotify
).
src/init.cpp
Outdated
|
||
boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex()); | ||
boost::thread t(runCommand, strCmd); // thread runs free | ||
if (!strCmd.empty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to test because in init.cpp
there's:
if (IsArgSet("-blocknotify"))
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does IsArgSet(…)
test for emptiness?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore if you want to keep the test here.
@promag I prefer doing a check inside of
|
Side note, should we treat empty args as invalid? |
@promag In the specific case of |
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. BTW: Why not handle this in |
It already does nothing! Same for |
@laanwj the only reason to test |
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 |
@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
|
To make BlockNotifyCallback(...) (-blocknotify) consistent with: * AlertNotify(...) (-alertnotify) * AddToWallet(...) (-walletnotify)
7f1ba9a
to
cffe85f
Compare
(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? |
Yes @jnewbery, IMO it can be improved. We should validate command line arguments in the same way we validate RPC arguments. Again, for me |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
We shouldn't make the empty command invalid so quickly: if one has (The alternative, |
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 Has anyone tested what happens with |
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 |
…r to executing cffe85f Skip sys::system(...) call in case of empty command (practicalswift) 6fb8f5f Check that -blocknotify command is non-empty before executing (practicalswift) Pull request description: Check that `-blocknotify` command is non-empty before executing. To make the `BlockNotifyCallback(...)` (`-blocknotify`) behaviour consistent with that of: * `AlertNotify(...)` (`-alertnotify`) * `AddToWallet(...)` (`-walletnotify`) Tree-SHA512: 18272166793a5a8b9cc2a727bfbcea53d38c329a55bc975c02db601329d608a61c20e026ce4b616193ecd3810dca4d3e2cb3bf773898a51872008a8dba96763e
…nd prior to executing cffe85f Skip sys::system(...) call in case of empty command (practicalswift) 6fb8f5f Check that -blocknotify command is non-empty before executing (practicalswift) Pull request description: Check that `-blocknotify` command is non-empty before executing. To make the `BlockNotifyCallback(...)` (`-blocknotify`) behaviour consistent with that of: * `AlertNotify(...)` (`-alertnotify`) * `AddToWallet(...)` (`-walletnotify`) Tree-SHA512: 18272166793a5a8b9cc2a727bfbcea53d38c329a55bc975c02db601329d608a61c20e026ce4b616193ecd3810dca4d3e2cb3bf773898a51872008a8dba96763e
…nd prior to executing cffe85f Skip sys::system(...) call in case of empty command (practicalswift) 6fb8f5f Check that -blocknotify command is non-empty before executing (practicalswift) Pull request description: Check that `-blocknotify` command is non-empty before executing. To make the `BlockNotifyCallback(...)` (`-blocknotify`) behaviour consistent with that of: * `AlertNotify(...)` (`-alertnotify`) * `AddToWallet(...)` (`-walletnotify`) Tree-SHA512: 18272166793a5a8b9cc2a727bfbcea53d38c329a55bc975c02db601329d608a61c20e026ce4b616193ecd3810dca4d3e2cb3bf773898a51872008a8dba96763e
…nd prior to executing cffe85f Skip sys::system(...) call in case of empty command (practicalswift) 6fb8f5f Check that -blocknotify command is non-empty before executing (practicalswift) Pull request description: Check that `-blocknotify` command is non-empty before executing. To make the `BlockNotifyCallback(...)` (`-blocknotify`) behaviour consistent with that of: * `AlertNotify(...)` (`-alertnotify`) * `AddToWallet(...)` (`-walletnotify`) Tree-SHA512: 18272166793a5a8b9cc2a727bfbcea53d38c329a55bc975c02db601329d608a61c20e026ce4b616193ecd3810dca4d3e2cb3bf773898a51872008a8dba96763e
…nd prior to executing cffe85f Skip sys::system(...) call in case of empty command (practicalswift) 6fb8f5f Check that -blocknotify command is non-empty before executing (practicalswift) Pull request description: Check that `-blocknotify` command is non-empty before executing. To make the `BlockNotifyCallback(...)` (`-blocknotify`) behaviour consistent with that of: * `AlertNotify(...)` (`-alertnotify`) * `AddToWallet(...)` (`-walletnotify`) Tree-SHA512: 18272166793a5a8b9cc2a727bfbcea53d38c329a55bc975c02db601329d608a61c20e026ce4b616193ecd3810dca4d3e2cb3bf773898a51872008a8dba96763e
…nd prior to executing cffe85f Skip sys::system(...) call in case of empty command (practicalswift) 6fb8f5f Check that -blocknotify command is non-empty before executing (practicalswift) Pull request description: Check that `-blocknotify` command is non-empty before executing. To make the `BlockNotifyCallback(...)` (`-blocknotify`) behaviour consistent with that of: * `AlertNotify(...)` (`-alertnotify`) * `AddToWallet(...)` (`-walletnotify`) Tree-SHA512: 18272166793a5a8b9cc2a727bfbcea53d38c329a55bc975c02db601329d608a61c20e026ce4b616193ecd3810dca4d3e2cb3bf773898a51872008a8dba96763e
Check that
-blocknotify
command is non-empty before executing.To make the
BlockNotifyCallback(...)
(-blocknotify
) behaviour consistent with that of:AlertNotify(...)
(-alertnotify
)AddToWallet(...)
(-walletnotify
)