aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bitcoind.cpp30
-rw-r--r--src/interfaces/node.cpp1
-rw-r--r--src/interfaces/node.h3
-rw-r--r--src/qt/bitcoin.cpp15
-rw-r--r--src/qt/bitcoin.h1
-rw-r--r--src/qt/bitcoingui.cpp3
6 files changed, 24 insertions, 29 deletions
diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp
index ba6de702e0..77367d6bb8 100644
--- a/src/bitcoind.cpp
+++ b/src/bitcoind.cpp
@@ -11,15 +11,14 @@
#include <clientversion.h>
#include <compat.h>
#include <fs.h>
-#include <interfaces/chain.h>
#include <init.h>
+#include <interfaces/chain.h>
#include <noui.h>
#include <shutdown.h>
+#include <ui_interface.h>
+#include <util/strencodings.h>
#include <util/system.h>
#include <util/threadnames.h>
-#include <util/strencodings.h>
-
-#include <stdio.h>
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
@@ -70,8 +69,7 @@ static bool AppInit(int argc, char* argv[])
SetupServerArgs();
std::string error;
if (!gArgs.ParseParameters(argc, argv, error)) {
- tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error.c_str());
- return false;
+ return InitError(strprintf("Error parsing command line arguments: %s\n", error));
}
// Process help and version before taking care about datadir
@@ -96,26 +94,22 @@ static bool AppInit(int argc, char* argv[])
{
if (!fs::is_directory(GetDataDir(false)))
{
- tfm::format(std::cerr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "").c_str());
- return false;
+ return InitError(strprintf("Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "")));
}
if (!gArgs.ReadConfigFiles(error, true)) {
- tfm::format(std::cerr, "Error reading configuration file: %s\n", error.c_str());
- return false;
+ return InitError(strprintf("Error reading configuration file: %s\n", error));
}
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
try {
SelectParams(gArgs.GetChainName());
} catch (const std::exception& e) {
- tfm::format(std::cerr, "Error: %s\n", e.what());
- return false;
+ return InitError(strprintf("%s\n", e.what()));
}
// Error out when loose non-argument tokens are encountered on command line
for (int i = 1; i < argc; i++) {
if (!IsSwitchChar(argv[i][0])) {
- tfm::format(std::cerr, "Error: Command line contains unexpected token '%s', see bitcoind -h for a list of options.\n", argv[i]);
- return false;
+ return InitError(strprintf("Command line contains unexpected token '%s', see bitcoind -h for a list of options.\n", argv[i]));
}
}
@@ -146,19 +140,17 @@ static bool AppInit(int argc, char* argv[])
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
- tfm::format(std::cout, "Bitcoin server starting\n");
+ tfm::format(std::cout, PACKAGE_NAME "daemon starting\n");
// Daemonize
if (daemon(1, 0)) { // don't chdir (1), do close FDs (0)
- tfm::format(std::cerr, "Error: daemon() failed: %s\n", strerror(errno));
- return false;
+ return InitError(strprintf("daemon() failed: %s\n", strerror(errno)));
}
#if defined(MAC_OSX)
#pragma GCC diagnostic pop
#endif
#else
- tfm::format(std::cerr, "Error: -daemon is not supported on this operating system\n");
- return false;
+ return InitError("-daemon is not supported on this operating system\n");
#endif // HAVE_DECL_DAEMON
}
// Lock data directory after daemonization
diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp
index 584d218dba..fd2fb6531b 100644
--- a/src/interfaces/node.cpp
+++ b/src/interfaces/node.cpp
@@ -54,6 +54,7 @@ class NodeImpl : public Node
{
public:
NodeImpl() { m_interfaces.chain = MakeChain(); }
+ void initError(const std::string& message) override { InitError(message); }
bool parseParameters(int argc, const char* const argv[], std::string& error) override
{
return gArgs.ParseParameters(argc, argv, error);
diff --git a/src/interfaces/node.h b/src/interfaces/node.h
index 1ccd2a31b7..bb4b3e1fae 100644
--- a/src/interfaces/node.h
+++ b/src/interfaces/node.h
@@ -38,6 +38,9 @@ class Node
public:
virtual ~Node() {}
+ //! Send init error.
+ virtual void initError(const std::string& message) = 0;
+
//! Set command line arguments.
virtual bool parseParameters(int argc, const char* const argv[], std::string& error) = 0;
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index 4a9742f7b7..ed5d47cad7 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -10,8 +10,8 @@
#include <qt/bitcoingui.h>
#include <chainparams.h>
-#include <qt/clientmodel.h>
#include <fs.h>
+#include <qt/clientmodel.h>
#include <qt/guiconstants.h>
#include <qt/guiutil.h>
#include <qt/intro.h>
@@ -30,15 +30,12 @@
#include <interfaces/handler.h>
#include <interfaces/node.h>
#include <noui.h>
-#include <util/threadnames.h>
#include <ui_interface.h>
#include <uint256.h>
#include <util/system.h>
+#include <util/threadnames.h>
#include <memory>
-#include <stdint.h>
-
-#include <boost/thread.hpp>
#include <QApplication>
#include <QDebug>
@@ -462,8 +459,11 @@ int GuiMain(int argc, char* argv[])
SetupUIArgs();
std::string error;
if (!node->parseParameters(argc, argv, error)) {
+ node->initError(strprintf("Error parsing command line arguments: %s\n", error));
+ // Create a message box, because the gui has neither been created nor has subscribed to core signals
QMessageBox::critical(nullptr, PACKAGE_NAME,
- QObject::tr("Error parsing command line arguments: %1.").arg(QString::fromStdString(error)));
+ // message can not be translated because translations have not been initialized
+ QString::fromStdString("Error parsing command line arguments: %1.").arg(QString::fromStdString(error)));
return EXIT_FAILURE;
}
@@ -499,11 +499,13 @@ int GuiMain(int argc, char* argv[])
/// - Do not call GetDataDir(true) before this step finishes
if (!fs::is_directory(GetDataDir(false)))
{
+ node->initError(strprintf("Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "")));
QMessageBox::critical(nullptr, PACKAGE_NAME,
QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(gArgs.GetArg("-datadir", ""))));
return EXIT_FAILURE;
}
if (!node->readConfigFiles(error)) {
+ node->initError(strprintf("Error reading configuration file: %s\n", error));
QMessageBox::critical(nullptr, PACKAGE_NAME,
QObject::tr("Error: Cannot parse configuration file: %1.").arg(QString::fromStdString(error)));
return EXIT_FAILURE;
@@ -519,6 +521,7 @@ int GuiMain(int argc, char* argv[])
try {
node->selectParams(gArgs.GetChainName());
} catch(std::exception &e) {
+ node->initError(strprintf("%s\n", e.what()));
QMessageBox::critical(nullptr, PACKAGE_NAME, QObject::tr("Error: %1").arg(e.what()));
return EXIT_FAILURE;
}
diff --git a/src/qt/bitcoin.h b/src/qt/bitcoin.h
index 370712d953..40537c1813 100644
--- a/src/qt/bitcoin.h
+++ b/src/qt/bitcoin.h
@@ -11,7 +11,6 @@
#include <QApplication>
#include <memory>
-#include <vector>
class BitcoinGUI;
class ClientModel;
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index c9a09573f9..3533227483 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -36,9 +36,6 @@
#include <ui_interface.h>
#include <util/system.h>
-#include <iostream>
-#include <memory>
-
#include <QAction>
#include <QApplication>
#include <QComboBox>