Skip to content
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

Merged
merged 2 commits into from Oct 4, 2017

Conversation

practicalswift
Copy link
Contributor

@practicalswift practicalswift commented Jul 26, 2017

Check that -blocknotify command is non-empty before executing.

To make the BlockNotifyCallback(...) (-blocknotify) behaviour consistent with that of:

  • AlertNotify(...) (-alertnotify)
  • AddToWallet(...) (-walletnotify)

@practicalswift practicalswift changed the title Check that -blocknotify command is non-empty before executing [init] Check that -blocknotify command is non-empty before executing Jul 26, 2017
@practicalswift practicalswift changed the title [init] Check that -blocknotify command is non-empty before executing [init] Check non-emptiness of -blocknotify command before executing Jul 26, 2017
@practicalswift practicalswift changed the title [init] Check non-emptiness of -blocknotify command before executing [init] Check non-emptiness of -blocknotify command prior to executing Jul 26, 2017
Copy link
Member

@promag promag left a 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.

@@ -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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated.

Copy link
Contributor Author

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()) {
Copy link
Member

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);

Copy link
Contributor Author

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?

Copy link
Member

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.

@practicalswift
Copy link
Contributor Author

practicalswift commented Jul 27, 2017

@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.
  • That is consistent with how it is done for AlertNotify(...) (-alertnotify) and AddToWallet(...) (-walletnotify).

@promag
Copy link
Member

promag commented Jul 27, 2017

Side note, should we treat empty args as invalid?

@practicalswift
Copy link
Contributor Author

practicalswift commented Jul 27, 2017

@promag In the specific case of -{alert,block,wallet}notify: yes - no need to execute "" :-)

@laanwj
Copy link
Member

laanwj commented Jul 27, 2017

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.

@laanwj
Copy link
Member

laanwj commented Jul 27, 2017

What does system("") do? spawn a shell?

It already does nothing! Same for system(" "); etc.
Why do we need this change?

@promag
Copy link
Member

promag commented Jul 27, 2017

@laanwj the only reason to test "" in each is to add some custom logging. Otherwise agree with you (despite the fact that we can avoid connecting to the signal in init).

@laanwj
Copy link
Member

laanwj commented Jul 27, 2017

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)

@practicalswift
Copy link
Contributor Author

practicalswift commented Jul 27, 2017

@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 :-)

@promag
Copy link
Member

promag commented Jul 31, 2017

@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)
@jnewbery
Copy link
Contributor

jnewbery commented Sep 1, 2017

(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?

@promag
Copy link
Member

promag commented Sep 1, 2017

Yes @jnewbery, IMO it can be improved. We should validate command line arguments in the same way we validate RPC arguments. Again, for me "" is an invalid command.

Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@luke-jr
Copy link
Member

luke-jr commented Sep 2, 2017

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...)

@promag
Copy link
Member

promag commented Sep 2, 2017

they may wish to use -blocknotify=

They can remove the line or comment it out?

@luke-jr
Copy link
Member

luke-jr commented Sep 2, 2017

Better if no change to the config file is needed for such a temporary purpose.

@jnewbery
Copy link
Contributor

jnewbery commented Sep 4, 2017

@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?

@laanwj
Copy link
Member

laanwj commented Oct 4, 2017

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

@laanwj laanwj merged commit cffe85f into bitcoin:master Oct 4, 2017
laanwj added a commit that referenced this pull request Oct 4, 2017
…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
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 31, 2020
…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
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 31, 2020
…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
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Feb 4, 2020
…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
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Feb 9, 2020
…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
@practicalswift practicalswift deleted the blocknotify-consistentcy branch April 10, 2021 19:32
gades pushed a commit to cosanta/cosanta-core that referenced this pull request Feb 15, 2022
…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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants