2018-05-16 19:17:40 +00:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2022-12-24 23:49:50 +00:00
|
|
|
// Copyright (c) 2009-2022 The Bitcoin Core developers
|
2018-05-16 19:17:40 +00:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <shutdown.h>
|
|
|
|
|
2022-05-02 16:37:31 +02:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
|
|
#include <config/bitcoin-config.h>
|
|
|
|
#endif
|
|
|
|
|
2023-06-01 16:53:33 -04:00
|
|
|
#include <kernel/context.h>
|
2021-01-26 19:34:47 +01:00
|
|
|
#include <logging.h>
|
2022-06-14 10:38:51 +02:00
|
|
|
#include <node/interface_ui.h>
|
2023-05-20 10:51:17 -03:00
|
|
|
#include <util/check.h>
|
2023-06-01 16:53:33 -04:00
|
|
|
#include <util/signalinterrupt.h>
|
2021-04-02 20:49:01 +02:00
|
|
|
#include <warnings.h>
|
2021-01-26 19:34:47 +01:00
|
|
|
|
2018-05-16 19:17:40 +00:00
|
|
|
#include <atomic>
|
2023-06-01 16:53:33 -04:00
|
|
|
#include <cassert>
|
2018-05-16 19:17:40 +00:00
|
|
|
|
2023-05-20 10:51:17 -03:00
|
|
|
static std::atomic<int>* g_exit_status{nullptr};
|
|
|
|
|
2021-04-02 20:49:01 +02:00
|
|
|
bool AbortNode(const std::string& strMessage, bilingual_str user_message)
|
|
|
|
{
|
|
|
|
SetMiscWarning(Untranslated(strMessage));
|
|
|
|
LogPrintf("*** %s\n", strMessage);
|
|
|
|
if (user_message.empty()) {
|
|
|
|
user_message = _("A fatal internal error occurred, see debug.log for details");
|
|
|
|
}
|
2023-02-24 13:44:07 -05:00
|
|
|
InitError(user_message);
|
2023-05-20 10:51:17 -03:00
|
|
|
Assert(g_exit_status)->store(EXIT_FAILURE);
|
2021-04-02 20:49:01 +02:00
|
|
|
StartShutdown();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-01 16:53:33 -04:00
|
|
|
void InitShutdownState(std::atomic<int>& exit_status)
|
2020-12-08 21:49:06 +01:00
|
|
|
{
|
2023-05-20 10:51:17 -03:00
|
|
|
g_exit_status = &exit_status;
|
2020-12-08 21:49:06 +01:00
|
|
|
}
|
2018-05-16 19:17:40 +00:00
|
|
|
|
|
|
|
void StartShutdown()
|
|
|
|
{
|
2023-06-01 16:53:33 -04:00
|
|
|
try {
|
|
|
|
Assert(kernel::g_context)->interrupt();
|
|
|
|
} catch (const std::system_error&) {
|
|
|
|
LogPrintf("Sending shutdown token failed\n");
|
|
|
|
assert(0);
|
2020-12-08 21:49:06 +01:00
|
|
|
}
|
2018-05-16 19:17:40 +00:00
|
|
|
}
|
2020-12-08 21:49:06 +01:00
|
|
|
|
2018-05-16 19:17:40 +00:00
|
|
|
void AbortShutdown()
|
|
|
|
{
|
2023-06-01 16:53:33 -04:00
|
|
|
Assert(kernel::g_context)->interrupt.reset();
|
2018-05-16 19:17:40 +00:00
|
|
|
}
|
2020-12-08 21:49:06 +01:00
|
|
|
|
2018-05-16 19:17:40 +00:00
|
|
|
bool ShutdownRequested()
|
|
|
|
{
|
2023-06-01 16:53:33 -04:00
|
|
|
return bool{Assert(kernel::g_context)->interrupt};
|
2018-05-16 19:17:40 +00:00
|
|
|
}
|
2020-12-08 21:49:06 +01:00
|
|
|
|
|
|
|
void WaitForShutdown()
|
|
|
|
{
|
2023-06-01 16:53:33 -04:00
|
|
|
try {
|
|
|
|
Assert(kernel::g_context)->interrupt.wait();
|
|
|
|
} catch (const std::system_error&) {
|
2021-01-26 19:34:47 +01:00
|
|
|
LogPrintf("Reading shutdown token failed\n");
|
|
|
|
assert(0);
|
2020-12-08 21:49:06 +01:00
|
|
|
}
|
|
|
|
}
|