diff options
author | Philip Kaufmann <phil.kaufmann@t-online.de> | 2012-06-11 07:40:14 +0200 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2012-06-14 17:53:59 +0000 |
commit | 276cfd85304be27bb2c04c087c8f3ea25cb6f77d (patch) | |
tree | e22604dbe955365b7696b5da3473c854419edf18 | |
parent | 0b1fda6f6542a309d59f511ab1c417f891a7237b (diff) |
Bugfix: Fix various places where Bitcoin-Qt was being shutdown improperly
(Partial/merge of upstream 9247134eaba9a1d0fa74f22de238af1476663005, 1a3f0da9229a8e524d1010cdc8bd3b9da71fe529, and 3e343522226e6c249f5cb05436eec347b87c6361)
-rw-r--r-- | src/bitcoinrpc.cpp | 13 | ||||
-rw-r--r-- | src/init.cpp | 11 | ||||
-rw-r--r-- | src/init.h | 1 | ||||
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/net.cpp | 2 | ||||
-rw-r--r-- | src/qt/bitcoin.cpp | 5 | ||||
-rw-r--r-- | src/qt/bitcoingui.cpp | 4 | ||||
-rw-r--r-- | src/qtui.h | 1 | ||||
-rw-r--r-- | src/test/test_bitcoin.cpp | 2 |
9 files changed, 26 insertions, 15 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 92f2f9ec7c..38f102e1ae 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -165,7 +165,8 @@ Value stop(const Array& params, bool fHelp) "Stop bitcoin server."); #ifndef QT_GUI // Shutdown will take long enough that the response should get back - CreateThread(Shutdown, NULL); + // NOTE: This should actually work with Bitcoin-Qt too now, but 0.5.0 didn't allow it + StartShutdown(); return "bitcoin server stopping"; #else throw runtime_error("NYI: cannot shut down GUI with RPC command"); @@ -1587,7 +1588,7 @@ Value encryptwallet(const Array& params, bool fHelp) // BDB seems to have a bad habit of writing old data into // slack space in .dat files; that is bad if the old data is // unencrypted private keys. So: - CreateThread(Shutdown, NULL); + StartShutdown(); return "wallet encrypted; bitcoin server stopping, restart to run with encrypted wallet"; } @@ -2173,10 +2174,6 @@ void ThreadRPCServer(void* parg) printf("ThreadRPCServer exiting\n"); } -#ifdef QT_GUI -extern bool HACK_SHUTDOWN; -#endif - void ThreadRPCServer2(void* parg) { printf("ThreadRPCServer started\n"); @@ -2203,7 +2200,7 @@ void ThreadRPCServer2(void* parg) EncodeBase58(&rand_pwd[0],&rand_pwd[0]+32).c_str()), _("Error"), wxOK | wxMODAL); #ifndef QT_GUI - CreateThread(Shutdown, NULL); + StartShutdown(); #endif return; } @@ -2228,9 +2225,9 @@ void ThreadRPCServer2(void* parg) } catch(boost::system::system_error &e) { - HACK_SHUTDOWN = true; ThreadSafeMessageBox(strprintf(_("An error occured while setting up the RPC port %i for listening: %s"), endpoint.port(), e.what()), _("Error"), wxOK | wxMODAL); + StartShutdown(); return; } #endif diff --git a/src/init.cpp b/src/init.cpp index 6b6a743af9..31e05514a2 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -41,6 +41,17 @@ void ExitTimeout(void* parg) #endif } +void StartShutdown() +{ +#ifdef QT_GUI + // ensure we leave the Qt main loop for a clean GUI exit (Shutdown() is called in bitcoin.cpp afterwards) + QueueShutdown(); +#else + // Without UI, Shutdown() can simply be started in a new thread + CreateThread(Shutdown, NULL); +#endif +} + void Shutdown(void* parg) { static CCriticalSection cs_Shutdown; diff --git a/src/init.h b/src/init.h index 2086b31348..6bf846628a 100644 --- a/src/init.h +++ b/src/init.h @@ -7,6 +7,7 @@ extern CWallet* pwalletMain; +void StartShutdown(); void Shutdown(void* parg); bool AppInit(int argc, char* argv[]); bool AppInit2(int argc, char* argv[]); diff --git a/src/main.cpp b/src/main.cpp index 792bbe97a4..a28d2e802a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1666,7 +1666,7 @@ bool CheckDiskSpace(uint64 nAdditionalBytes) strMiscWarning = strMessage; printf("*** %s\n", strMessage.c_str()); ThreadSafeMessageBox(strMessage, "Bitcoin", wxOK | wxICON_EXCLAMATION); - CreateThread(Shutdown, NULL); + StartShutdown(); return false; } return true; diff --git a/src/net.cpp b/src/net.cpp index e1eea0d1b3..ebdc1cc149 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1705,7 +1705,7 @@ void ThreadMessageHandler2(void* parg) vnThreadsRunning[2]--; Sleep(100); if (fRequestShutdown) - Shutdown(NULL); + StartShutdown(); vnThreadsRunning[2]++; if (fShutdown) return; diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 8dde8f3b29..6986d39cbf 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -112,6 +112,11 @@ void InitMessage(const std::string &message) } } +void QueueShutdown() +{ + QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection); +} + /* Translate string to current locale using Qt. */ diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 778acd1e00..2c807a1ae4 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -519,16 +519,12 @@ void BitcoinGUI::refreshStatusBar() setNumBlocks(clientModel->getNumBlocks()); } -bool HACK_SHUTDOWN = false; - void BitcoinGUI::error(const QString &title, const QString &message, bool modal) { // Report errors from network/worker thread if (modal) { QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok); - if (HACK_SHUTDOWN) - QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection); } else { notificator->notify(Notificator::Critical, title, message); } diff --git a/src/qtui.h b/src/qtui.h index 8f3e139ec8..52983b87e7 100644 --- a/src/qtui.h +++ b/src/qtui.h @@ -45,6 +45,7 @@ extern bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, extern void CalledSetStatusBar(const std::string& strText, int nField); extern void UIThreadCall(boost::function0<void> fn); extern void MainFrameRepaint(); +extern void QueueShutdown(); extern void InitMessage(const std::string &message); extern std::string _(const char* psz); diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index 39a7c88e13..ca001b0e67 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -17,7 +17,7 @@ CWallet* pwalletMain; -void Shutdown(void* parg) +void StartShutdown() { exit(0); } |