gui: return EXIT_FAILURE on post-init fatal errors

This commit is contained in:
furszy 2023-06-08 12:16:23 -03:00
parent 3b2c61e819
commit 4927167f85
No known key found for this signature in database
GPG Key ID: 5DD23CCC686AA623
4 changed files with 12 additions and 12 deletions

View File

@ -80,6 +80,9 @@ public:
//! Get warnings. //! Get warnings.
virtual bilingual_str getWarnings() = 0; virtual bilingual_str getWarnings() = 0;
//! Get exit status.
virtual int getExitStatus() = 0;
// Get log flags. // Get log flags.
virtual uint32_t getLogCategories() = 0; virtual uint32_t getLogCategories() = 0;

View File

@ -89,6 +89,7 @@ public:
void initLogging() override { InitLogging(args()); } void initLogging() override { InitLogging(args()); }
void initParameterInteraction() override { InitParameterInteraction(args()); } void initParameterInteraction() override { InitParameterInteraction(args()); }
bilingual_str getWarnings() override { return GetWarnings(true); } bilingual_str getWarnings() override { return GetWarnings(true); }
int getExitStatus() override { return Assert(m_context)->exit_status.load(); }
uint32_t getLogCategories() override { return LogInstance().GetCategoryMask(); } uint32_t getLogCategories() override { return LogInstance().GetCategoryMask(); }
bool baseInitialize() override bool baseInitialize() override
{ {
@ -105,7 +106,10 @@ public:
} }
bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info) override bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info) override
{ {
return AppInitMain(*m_context, tip_info); if (AppInitMain(*m_context, tip_info)) return true;
// Error during initialization, set exit status before continue
m_context->exit_status.store(EXIT_FAILURE);
return false;
} }
void appShutdown() override void appShutdown() override
{ {

View File

@ -9,6 +9,7 @@
#include <qt/bitcoin.h> #include <qt/bitcoin.h>
#include <chainparams.h> #include <chainparams.h>
#include <node/context.h>
#include <common/args.h> #include <common/args.h>
#include <common/init.h> #include <common/init.h>
#include <common/system.h> #include <common/system.h>
@ -397,9 +398,7 @@ void BitcoinApplication::initializeResult(bool success, interfaces::BlockAndHead
{ {
qDebug() << __func__ << ": Initialization result: " << success; qDebug() << __func__ << ": Initialization result: " << success;
// Set exit result. if (success) {
returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE;
if(success) {
delete m_splash; delete m_splash;
m_splash = nullptr; m_splash = nullptr;
@ -653,7 +652,6 @@ int GuiMain(int argc, char* argv[])
app.InitPruneSetting(prune_MiB); app.InitPruneSetting(prune_MiB);
} }
int rv = EXIT_SUCCESS;
try try
{ {
app.createWindow(networkStyle.data()); app.createWindow(networkStyle.data());
@ -666,10 +664,9 @@ int GuiMain(int argc, char* argv[])
WinShutdownMonitor::registerShutdownBlockReason(QObject::tr("%1 didn't yet exit safely…").arg(PACKAGE_NAME), (HWND)app.getMainWinId()); WinShutdownMonitor::registerShutdownBlockReason(QObject::tr("%1 didn't yet exit safely…").arg(PACKAGE_NAME), (HWND)app.getMainWinId());
#endif #endif
app.exec(); app.exec();
rv = app.getReturnValue();
} else { } else {
// A dialog with detailed error will have been shown by InitError() // A dialog with detailed error will have been shown by InitError()
rv = EXIT_FAILURE; return EXIT_FAILURE;
} }
} catch (const std::exception& e) { } catch (const std::exception& e) {
PrintExceptionContinue(&e, "Runaway exception"); PrintExceptionContinue(&e, "Runaway exception");
@ -678,5 +675,5 @@ int GuiMain(int argc, char* argv[])
PrintExceptionContinue(nullptr, "Runaway exception"); PrintExceptionContinue(nullptr, "Runaway exception");
app.handleRunawayException(QString::fromStdString(app.node().getWarnings().translated)); app.handleRunawayException(QString::fromStdString(app.node().getWarnings().translated));
} }
return rv; return app.node().getExitStatus();
} }

View File

@ -62,9 +62,6 @@ public:
/// Request core initialization /// Request core initialization
void requestInitialize(); void requestInitialize();
/// Get process return value
int getReturnValue() const { return returnValue; }
/// Get window identifier of QMainWindow (BitcoinGUI) /// Get window identifier of QMainWindow (BitcoinGUI)
WId getMainWinId() const; WId getMainWinId() const;
@ -104,7 +101,6 @@ private:
PaymentServer* paymentServer{nullptr}; PaymentServer* paymentServer{nullptr};
WalletController* m_wallet_controller{nullptr}; WalletController* m_wallet_controller{nullptr};
#endif #endif
int returnValue{0};
const PlatformStyle* platformStyle{nullptr}; const PlatformStyle* platformStyle{nullptr};
std::unique_ptr<QWidget> shutdownWindow; std::unique_ptr<QWidget> shutdownWindow;
SplashScreen* m_splash = nullptr; SplashScreen* m_splash = nullptr;