aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac17
-rw-r--r--src/qt/walletcontroller.cpp12
-rw-r--r--src/qt/walletcontroller.h1
-rw-r--r--src/util/time.cpp12
-rw-r--r--src/wallet/load.cpp26
-rw-r--r--src/wallet/wallet.cpp25
-rwxr-xr-xtest/functional/wallet_multiwallet.py4
7 files changed, 66 insertions, 31 deletions
diff --git a/configure.ac b/configure.ac
index 1f85dd3a99..4cfd5c9274 100644
--- a/configure.ac
+++ b/configure.ac
@@ -906,6 +906,22 @@ if test "x$use_thread_local" = xyes || { test "x$use_thread_local" = xauto && te
LDFLAGS="$TEMP_LDFLAGS"
fi
+dnl check for gmtime_r(), fallback to gmtime_s() if that is unavailable
+dnl fail if neither are available.
+AC_MSG_CHECKING(for gmtime_r)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <ctime>]],
+ [[ gmtime_r((const time_t *) nullptr, (struct tm *) nullptr); ]])],
+ [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_GMTIME_R, 1, [Define this symbol if gmtime_r is available]) ],
+ [ AC_MSG_RESULT(no);
+ AC_MSG_CHECKING(for gmtime_s);
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <ctime>]],
+ [[ gmtime_s((struct tm *) nullptr, (const time_t *) nullptr); ]])],
+ [ AC_MSG_RESULT(yes)],
+ [ AC_MSG_RESULT(no); AC_MSG_ERROR(Both gmtime_r and gmtime_s are unavailable) ]
+ )
+ ]
+)
+
dnl Check for different ways of gathering OS randomness
AC_MSG_CHECKING(for Linux getrandom syscall)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>
@@ -1596,6 +1612,7 @@ AC_SUBST(EVENT_LIBS)
AC_SUBST(EVENT_PTHREADS_LIBS)
AC_SUBST(ZMQ_LIBS)
AC_SUBST(QR_LIBS)
+AC_SUBST(HAVE_GMTIME_R)
AC_SUBST(HAVE_FDATASYNC)
AC_SUBST(HAVE_FULLFSYNC)
AC_SUBST(HAVE_O_CLOEXEC)
diff --git a/src/qt/walletcontroller.cpp b/src/qt/walletcontroller.cpp
index 88c694567e..f076b5ba61 100644
--- a/src/qt/walletcontroller.cpp
+++ b/src/qt/walletcontroller.cpp
@@ -166,6 +166,7 @@ WalletControllerActivity::~WalletControllerActivity()
void WalletControllerActivity::showProgressDialog(const QString& label_text)
{
+ assert(!m_progress_dialog);
m_progress_dialog = new QProgressDialog(m_parent_widget);
m_progress_dialog->setLabelText(label_text);
@@ -175,6 +176,13 @@ void WalletControllerActivity::showProgressDialog(const QString& label_text)
GUIUtil::PolishProgressDialog(m_progress_dialog);
}
+void WalletControllerActivity::destroyProgressDialog()
+{
+ assert(m_progress_dialog);
+ delete m_progress_dialog;
+ m_progress_dialog = nullptr;
+}
+
CreateWalletActivity::CreateWalletActivity(WalletController* wallet_controller, QWidget* parent_widget)
: WalletControllerActivity(wallet_controller, parent_widget)
{
@@ -229,7 +237,7 @@ void CreateWalletActivity::createWallet()
void CreateWalletActivity::finish()
{
- m_progress_dialog->hide();
+ destroyProgressDialog();
if (!m_error_message.empty()) {
QMessageBox::critical(m_parent_widget, tr("Create wallet failed"), QString::fromStdString(m_error_message));
@@ -270,7 +278,7 @@ OpenWalletActivity::OpenWalletActivity(WalletController* wallet_controller, QWid
void OpenWalletActivity::finish()
{
- m_progress_dialog->hide();
+ destroyProgressDialog();
if (!m_error_message.empty()) {
QMessageBox::critical(m_parent_widget, tr("Open wallet failed"), QString::fromStdString(m_error_message));
diff --git a/src/qt/walletcontroller.h b/src/qt/walletcontroller.h
index 956245775e..f30eb25308 100644
--- a/src/qt/walletcontroller.h
+++ b/src/qt/walletcontroller.h
@@ -96,6 +96,7 @@ protected:
QObject* worker() const { return m_wallet_controller->m_activity_worker; }
void showProgressDialog(const QString& label_text);
+ void destroyProgressDialog();
WalletController* const m_wallet_controller;
QWidget* const m_parent_widget;
diff --git a/src/util/time.cpp b/src/util/time.cpp
index 14937b985e..0938ff36a6 100644
--- a/src/util/time.cpp
+++ b/src/util/time.cpp
@@ -78,10 +78,10 @@ int64_t GetSystemTimeInSeconds()
std::string FormatISO8601DateTime(int64_t nTime) {
struct tm ts;
time_t time_val = nTime;
-#ifdef _MSC_VER
- if (gmtime_s(&ts, &time_val) != 0) {
-#else
+#ifdef HAVE_GMTIME_R
if (gmtime_r(&time_val, &ts) == nullptr) {
+#else
+ if (gmtime_s(&ts, &time_val) != 0) {
#endif
return {};
}
@@ -91,10 +91,10 @@ std::string FormatISO8601DateTime(int64_t nTime) {
std::string FormatISO8601Date(int64_t nTime) {
struct tm ts;
time_t time_val = nTime;
-#ifdef _MSC_VER
- if (gmtime_s(&ts, &time_val) != 0) {
-#else
+#ifdef HAVE_GMTIME_R
if (gmtime_r(&time_val, &ts) == nullptr) {
+#else
+ if (gmtime_s(&ts, &time_val) != 0) {
#endif
return {};
}
diff --git a/src/wallet/load.cpp b/src/wallet/load.cpp
index 3e92c07d64..d6e44c7be5 100644
--- a/src/wallet/load.cpp
+++ b/src/wallet/load.cpp
@@ -66,19 +66,23 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
bool LoadWallets(interfaces::Chain& chain, const std::vector<std::string>& wallet_files)
{
- for (const std::string& walletFile : wallet_files) {
- std::string error;
- std::vector<std::string> warnings;
- std::shared_ptr<CWallet> pwallet = CWallet::CreateWalletFromFile(chain, WalletLocation(walletFile), error, warnings);
- if (!warnings.empty()) chain.initWarning(Join(warnings, "\n"));
- if (!pwallet) {
- chain.initError(error);
- return false;
+ try {
+ for (const std::string& walletFile : wallet_files) {
+ std::string error;
+ std::vector<std::string> warnings;
+ std::shared_ptr<CWallet> pwallet = CWallet::CreateWalletFromFile(chain, WalletLocation(walletFile), error, warnings);
+ if (!warnings.empty()) chain.initWarning(Join(warnings, "\n"));
+ if (!pwallet) {
+ chain.initError(error);
+ return false;
+ }
+ AddWallet(pwallet);
}
- AddWallet(pwallet);
+ return true;
+ } catch (const std::runtime_error& e) {
+ chain.initError(e.what());
+ return false;
}
-
- return true;
}
void StartWallets(CScheduler& scheduler)
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 98f308f927..bc9f84a11d 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -148,19 +148,24 @@ void UnloadWallet(std::shared_ptr<CWallet>&& wallet)
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const WalletLocation& location, std::string& error, std::vector<std::string>& warnings)
{
- if (!CWallet::Verify(chain, location, false, error, warnings)) {
- error = "Wallet file verification failed: " + error;
- return nullptr;
- }
+ try {
+ if (!CWallet::Verify(chain, location, false, error, warnings)) {
+ error = "Wallet file verification failed: " + error;
+ return nullptr;
+ }
- std::shared_ptr<CWallet> wallet = CWallet::CreateWalletFromFile(chain, location, error, warnings);
- if (!wallet) {
- error = "Wallet loading failed: " + error;
+ std::shared_ptr<CWallet> wallet = CWallet::CreateWalletFromFile(chain, location, error, warnings);
+ if (!wallet) {
+ error = "Wallet loading failed: " + error;
+ return nullptr;
+ }
+ AddWallet(wallet);
+ wallet->postInitProcess();
+ return wallet;
+ } catch (const std::runtime_error& e) {
+ error = e.what();
return nullptr;
}
- AddWallet(wallet);
- wallet->postInitProcess();
- return wallet;
}
std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const std::string& name, std::string& error, std::vector<std::string>& warnings)
diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py
index 78ead514a5..a2c502f280 100755
--- a/test/functional/wallet_multiwallet.py
+++ b/test/functional/wallet_multiwallet.py
@@ -236,10 +236,10 @@ class MultiWalletTest(BitcoinTestFramework):
assert_raises_rpc_error(-4, "Wallet file verification failed: Error loading wallet wallet.dat. Duplicate -wallet filename specified.", self.nodes[0].loadwallet, 'wallet.dat')
# Fail to load if one wallet is a copy of another
- assert_raises_rpc_error(-1, "BerkeleyBatch: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
+ assert_raises_rpc_error(-4, "BerkeleyBatch: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
# Fail to load if one wallet is a copy of another, test this twice to make sure that we don't re-introduce #14304
- assert_raises_rpc_error(-1, "BerkeleyBatch: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
+ assert_raises_rpc_error(-4, "BerkeleyBatch: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
# Fail to load if wallet file is a symlink