Skip to content

Commit 4927167

Browse files
committed
gui: return EXIT_FAILURE on post-init fatal errors
1 parent 3b2c61e commit 4927167

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/interfaces/node.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ class Node
8080
//! Get warnings.
8181
virtual bilingual_str getWarnings() = 0;
8282

83+
//! Get exit status.
84+
virtual int getExitStatus() = 0;
85+
8386
// Get log flags.
8487
virtual uint32_t getLogCategories() = 0;
8588

src/node/interfaces.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class NodeImpl : public Node
8989
void initLogging() override { InitLogging(args()); }
9090
void initParameterInteraction() override { InitParameterInteraction(args()); }
9191
bilingual_str getWarnings() override { return GetWarnings(true); }
92+
int getExitStatus() override { return Assert(m_context)->exit_status.load(); }
9293
uint32_t getLogCategories() override { return LogInstance().GetCategoryMask(); }
9394
bool baseInitialize() override
9495
{
@@ -105,7 +106,10 @@ class NodeImpl : public Node
105106
}
106107
bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info) override
107108
{
108-
return AppInitMain(*m_context, tip_info);
109+
if (AppInitMain(*m_context, tip_info)) return true;
110+
// Error during initialization, set exit status before continue
111+
m_context->exit_status.store(EXIT_FAILURE);
112+
return false;
109113
}
110114
void appShutdown() override
111115
{

src/qt/bitcoin.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <qt/bitcoin.h>
1010

1111
#include <chainparams.h>
12+
#include <node/context.h>
1213
#include <common/args.h>
1314
#include <common/init.h>
1415
#include <common/system.h>
@@ -397,9 +398,7 @@ void BitcoinApplication::initializeResult(bool success, interfaces::BlockAndHead
397398
{
398399
qDebug() << __func__ << ": Initialization result: " << success;
399400

400-
// Set exit result.
401-
returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE;
402-
if(success) {
401+
if (success) {
403402
delete m_splash;
404403
m_splash = nullptr;
405404

@@ -653,7 +652,6 @@ int GuiMain(int argc, char* argv[])
653652
app.InitPruneSetting(prune_MiB);
654653
}
655654

656-
int rv = EXIT_SUCCESS;
657655
try
658656
{
659657
app.createWindow(networkStyle.data());
@@ -666,10 +664,9 @@ int GuiMain(int argc, char* argv[])
666664
WinShutdownMonitor::registerShutdownBlockReason(QObject::tr("%1 didn't yet exit safely…").arg(PACKAGE_NAME), (HWND)app.getMainWinId());
667665
#endif
668666
app.exec();
669-
rv = app.getReturnValue();
670667
} else {
671668
// A dialog with detailed error will have been shown by InitError()
672-
rv = EXIT_FAILURE;
669+
return EXIT_FAILURE;
673670
}
674671
} catch (const std::exception& e) {
675672
PrintExceptionContinue(&e, "Runaway exception");
@@ -678,5 +675,5 @@ int GuiMain(int argc, char* argv[])
678675
PrintExceptionContinue(nullptr, "Runaway exception");
679676
app.handleRunawayException(QString::fromStdString(app.node().getWarnings().translated));
680677
}
681-
return rv;
678+
return app.node().getExitStatus();
682679
}

src/qt/bitcoin.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ class BitcoinApplication: public QApplication
6262
/// Request core initialization
6363
void requestInitialize();
6464

65-
/// Get process return value
66-
int getReturnValue() const { return returnValue; }
67-
6865
/// Get window identifier of QMainWindow (BitcoinGUI)
6966
WId getMainWinId() const;
7067

@@ -104,7 +101,6 @@ public Q_SLOTS:
104101
PaymentServer* paymentServer{nullptr};
105102
WalletController* m_wallet_controller{nullptr};
106103
#endif
107-
int returnValue{0};
108104
const PlatformStyle* platformStyle{nullptr};
109105
std::unique_ptr<QWidget> shutdownWindow;
110106
SplashScreen* m_splash = nullptr;

0 commit comments

Comments
 (0)