10000 Use subprocess library for notifications by laanwj · Pull Request #32566 · bitcoin/bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use subprocess library for notifications #32566

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

laanwj
Copy link
Member
@laanwj laanwj commented May 19, 2025

Builds on #29868 (to have windows support).

This switches the -*notify options to use the subprocess library, which is currently used for only the external signer. The main advantage of this is that file descriptor leaks are avoided (#32343). This could also add future flexibility in notifications, for example to bypass the shell (and launch commands with their arguments directly[1]), or do something with command output (like log it). But for now, this is meant to be one-to-one.

  • Generalize ENABLE_EXTERNAL_SIGNER build option to ENABLE_SUBPROCESS.
  • Unify everything dealing with external commands in common/run_command.cpp. Use the new functions RunShell and RunShellInThread.
  • Remove HAVE_SYSTEM.

[1] There's a long-running issue on Windows where it can't pass the wallet name because there's no way to escape it for the shell.

@DrahtBot
Copy link
Contributor
DrahtBot commented May 19, 2025

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32566.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK fanquake, hebasto, theStack

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #32528 (rpc: Round verificationprogress to 1 for a recent tip by maflcko)
  • #29641 (scripted-diff: Use LogInfo over LogPrintf [WIP, NOMERGE, DRAFT] by maflcko)
  • #28792 (Embed default ASMap as binary dump header file by fjahr)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@laanwj laanwj force-pushed the 2025-05-subprocess-system branch from 397ff54 to 7b25522 Compare May 19, 2025 14:59
@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/runs/42487791631
LLM reason (✨ experimental): The CI failure is due to a lint check indicating unused includes of the bitcoin-build-config.h header.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@laanwj laanwj force-pushed the 2025-05-subprocess-system branch 3 times, most recently from 8aebdab to e32bfc4 Compare May 19, 2025 15:43
@fanquake
Copy link
Member

Concept ACK. Seems like there is some overlap here with #32380, but that this PR should go first, otherwise #32380 is going to be refactoring code, that is being deleted here.

@laanwj
Copy link
Member Author
laanwj commented May 19, 2025

i'm not 100% sure ENABLE_SUBPROCESS needs to exist as an option at all, btw, it may be something to always enable, but maybe not on mobile/sandboxed platforms so wasn't sure whether to make that decision here.

Edit: most notably, the ENABLE_SUBPROCESS=OFF path isn't tested in the CI at all, it probably should? but in what run?

@hebasto
Copy link
Member
hebasto commented May 19, 2025

Concept ACK.

Seems like there is some overlap here with #32380, but that this PR should go first, otherwise #32380 is going to be refactoring code, that is being deleted here.

I agree. And we are not going to switch to C++26 any time soon when #32380 will be required.

@theStack
Copy link
Contributor

Concept ACK

@laanwj laanwj force-pushed the 2025-05-subprocess-system branch 4 times, most recently from 9069ed3 to 722cd1d Compare May 19, 2025 17:44
@laanwj laanwj force-pushed the 2025-05-subprocess-system branch 3 times, most recently from ec5c0c0 to 27d4ae1 Compare May 19, 2025 20:44
@laanwj laanwj force-pushed the 2025-05-subprocess-system branch from 27d4ae1 to 02d7fb6 Compare May 19, 2025 22:03
@laanwj laanwj force-pushed the 2025-05-subprocess-system branch from 02d7fb6 to 56fb60a Compare May 20, 2025 07:45
@laanwj laanwj force-pushed the 2025-05-subprocess-system branch 2 times, most recently from 9de7029 to 2193963 Compare May 20, 2025 09:13
@laanwj laanwj force-pushed the 2025-05-subprocess-system branch 2 times, most recently from 14362bc to ceb1783 Compare May 20, 2025 14:51

#ifdef ENABLE_EXTERNAL_SIGNER
#ifdef ENABLE_SUBPROCESS
Copy link
Member

Choose a reason for hiding this comment

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

I think you can just drop these #ifdefs around our own headers. Same for in RunCommandParseJSON below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Wasn't sure about this. One reason for setting ENABLE_SUBPROCESS=OFF in the first place would be that the operating system doesn't support subprocesses. As subprocess is a header-only library, including the subprocess.hpp header would mean use of fork execv CreateProcessW etc. So it could break the compile.

Copy link
Member Author
@laanwj laanwj May 21, 2025

Choose a reason for hiding this comment

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

If we don't care about supporting such operating systems (only iOS comes to mind), it would imo be preferable to remove the option entirely (and with it, all the ifdefs).

Copy link
Member

Choose a reason for hiding this comment

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

I think I agree. Given we don't actually test or ship anything for iOS, it seems like we can clean up the code now, and figure out what to do if/when this might be an issue later.

auto c = sp::Popen("cmd.exe /c " + str_command);
#else
// Emulate system(3) behavior, but don't leak file descriptors.
auto c = sp::Popen({"/bin/sh", "-c", str_command}, sp::close_fds{true});
Copy link
Member Author

Choose a reason for hiding this comment

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

TIL that upstream subprocess has a shell option that does the equivalent (https://github.com/arun11299/cpp-subprocess/blob/master/cpp-subprocess/subprocess.hpp#L1630) . But we removed it.

Unfortunately, currently it doesn't support Windows. Could revert the option and switch to using that, when it does. Or, unless they had reason to not do it in the trivial way we do, it seems easy to add.

Copy link
Member

Choose a reason for hiding this comment

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

A related discussion takes place at #32577.

Copy link
Member
@hebasto hebasto May 23, 2025

Choose a reason for hiding this comment

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

This is the first use of the Popen(std::initializer_list<const char*> cmd_args, Args&& ...args) ctor. Before this, it was a candidate for cleanup.

fanquake added a commit that referenced this pull request May 21, 2025
e63a703 subprocess: Don't add an extra whitespace at end of Windows command line (laanwj)

Pull request description:

  A list of the backported PRs:
  - arun11299/cpp-subprocess#119

  The following PRs were skipped for backporting:
  - arun11299/cpp-subprocess#118 because there is no changes in the header code.

  Required for #32566.

ACKs for top commit:
  laanwj:
    Code review ACK e63a703

Tree-SHA512: 69a74aa7f9c611a9ec910e27161c5e9e147067d37f8335953cd3875fcc88dc840a2f7b206bb603f22507159e406b1449f1dc4702fffe890bb824672641b4feed
@laanwj laanwj force-pushed the 2025-05-subprocess-system branch from ceb1783 to 82aeba6 Compare May 21, 2025 11:41
@laanwj
Copy link
Member Author
laanwj commented May 21, 2025

@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0