init: Return EXIT_SUCCESS on interrupt #34224

pull sedited wants to merge 1 commits into bitcoin:master from sedited:init_interrupt_zero changing 2 files +41 −40
  1. sedited commented at 10:24 pm on January 7, 2026: contributor

    Reported by dergoegge on irc.

    An interrupt does not create a failure exit code during normal operation. This should also be the case when interrupt is triggered during initialization. However a failure exit code is currently returned if an interrupt occurs during init. Fix this by making AppInitMain return true instead of false on interrupt, which further up the call stack currently sets the EXIT_FAILURE code. Also add a check for the interrupt condition during GUI startup.

    Best reviewed with --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space.

  2. DrahtBot commented at 10:25 pm on January 7, 2026: contributor

    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/34224.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK maflcko, janb84, dergoegge
    Concept ACK bensig

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    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.

  3. bensig commented at 11:23 pm on January 7, 2026: contributor
    Concept ACK 3dbbac09f25a8337b75858a42386c8d7f8f1af92
  4. DrahtBot added the label CI failed on Jan 7, 2026
  5. DrahtBot removed the label CI failed on Jan 8, 2026
  6. dergoegge approved
  7. dergoegge commented at 3:26 pm on January 8, 2026: member
    Code review ACK 3dbbac09f25a8337b75858a42386c8d7f8f1af92
  8. maflcko commented at 5:19 pm on January 8, 2026: member

    I don’t think this works. At least locally, I am still seeing 1 when I ^C later. I used a diff to make this easier to test:

     0diff --git a/src/init.cpp b/src/init.cpp
     1index f2af858eb4..b6e903c497 100644
     2--- a/src/init.cpp
     3+++ b/src/init.cpp
     4@@ -1828,2 +1828,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
     5 
     6+    std::cout << "a\n";
     7+    UninterruptibleSleep(1s);
     8+    std::cout << "b\n";
     9+
    10     // As LoadBlockIndex can take several minutes, it's possible the user
    

    So it now works fine when pressing ^C before b is printed, but not after:

    0$ ./bld-cmake/bin/bitcoind -noprinttoconsole=1 
    1a
    2^Cb
    3$ echo $?
    40  # works correctly
    5$ ./bld-cmake/bin/bitcoind -noprinttoconsole=1 
    6a
    7b
    8^C $?
    91  # wrong exit code?
    
  9. init: Fix non-zero code on interrupt
    An interrupt does not create a failure exit code during normal
    operation. This should also be the case when interrupt is triggered
    during initialization. However a failure exit code is currently returned
    if an interrupt occurs during init. Fix this by making `AppInitMain` return
    true instead of false, which further up the call stack sets the
    `EXIT_FAILURE` code. Also add a check for the interrupt condition during
    GUI startup.
    997e7b4d7c
  10. sedited force-pushed on Jan 8, 2026
  11. sedited commented at 7:37 pm on January 8, 2026: contributor

    Updated 3dbbac09f25a8337b75858a42386c8d7f8f1af92 -> 997e7b4d7cf7c4622938798423447375383184c0 (init_interrupt_zero_0 -> init_interrupt_zero_1, compare)

    • Addressed @maflcko’s comment, added previously missed case for returning after a shutdown is detected. These are kind of difficult to find exhaustively, but I did reproduce the missing case too, and this seems to fix it for me.
  12. maflcko commented at 7:55 pm on January 8, 2026: member

    review ACK 997e7b4d7cf7c4622938798423447375383184c0 🔺

    Signature:

    0untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
    1RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
    2trusted comment: review ACK 997e7b4d7cf7c4622938798423447375383184c0 🔺
    37kAK1PhE4TRlfj2lMDMYSH0Tv1kSe6YM9Cw6AfqLtacMJiC4gTxuBXuEbmNxNjE5AQEbnvhFG/hFZ1oTv9tJAw==
    
  13. DrahtBot requested review from dergoegge on Jan 8, 2026
  14. janb84 commented at 8:39 pm on January 8, 2026: contributor

    ACK 997e7b4d7cf7c4622938798423447375383184c0

    PR fixes exit code on SIGINT while being in init.

    While I was first under the impression that the exit code should be 130 (as per Advanced Bash-Scripting Guide:) because of SIGINT, this is not the case. SIGINT is correctly handled by the application ending in a clean shutdown so it should be 0 (which is the case after this PR)

    e.g. killing a bitcoin node with SIGKILL results in a 137

    02026-01-08T20:26:49Z dnsseed thread exit
    1Killed: 9                  ./bitcoind --regtest
    2
    3[nix-shell:~/Projects/bitcoin/build_dev_mode/bin]$ echo $?
    4137
    
  15. dergoegge approved
  16. dergoegge commented at 10:58 am on January 9, 2026: member
    utACK 997e7b4d7cf7c4622938798423447375383184c0

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-01-12 03:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me