aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@protonmail.com>2020-12-08 21:49:06 +0100
committerWladimir J. van der Laan <laanwj@protonmail.com>2020-12-15 17:21:06 +0100
commitcd03513dc2fcccaa142e9632a28b38efd0056436 (patch)
tree639d20a2fe5c505279d276517d3ddd868c812ba0 /src/init.cpp
parent16b31cc4c516cdcaf6d2eb2dd1255cc3e6973ba1 (diff)
downloadbitcoin-cd03513dc2fcccaa142e9632a28b38efd0056436.tar.xz
init: Signal-safe instant shutdown
Replace the 200ms polling loop with a faster and more efficient waiting operation. This was tried a few times before, but given up every time because solutions use a condition variable which is not safe for use in signals as they need to be reentrant. On UNIX-ish OSes, use a safe way: a pipe. When shutdown is requested write a dummy byte to the pipe. Waiting for shutdown is a matter of a blocking read from the pipe. On Windows, there are no signals so using a condition variable is safe.
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 371399de9e..a9d8e7e40c 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -917,6 +917,9 @@ bool AppInitBasicSetup(const ArgsManager& args)
// Enable heap terminate-on-corruption
HeapSetInformation(nullptr, HeapEnableTerminationOnCorruption, nullptr, 0);
#endif
+ if (!InitShutdownState()) {
+ return InitError(Untranslated("Initializing wait-for-shutdown state failed."));
+ }
if (!SetupNetworking()) {
return InitError(Untranslated("Initializing networking failed."));