diff --git a/src/init.cpp b/src/init.cpp index 15ee267c04c4..1e3f1d5d9431 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -828,8 +828,11 @@ bool AppInit2(boost::thread_group& threadGroup) FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist. if (file) fclose(file); static boost::interprocess::file_lock lock(pathLockFile.string().c_str()); - if (!lock.try_lock()) + + // Wait maximum 10 seconds if an old wallet is still running. Avoids lockup during restart + if (!lock.timed_lock(boost::get_system_time() + boost::posix_time::seconds(10))) return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Dash Core is probably already running."), strDataDir)); + #ifndef WIN32 CreatePidFile(GetPidFile(), getpid()); #endif diff --git a/src/qt/dash.cpp b/src/qt/dash.cpp index 5a6860ef18fd..b10ffeb3fb92 100644 --- a/src/qt/dash.cpp +++ b/src/qt/dash.cpp @@ -185,6 +185,9 @@ public slots: private: boost::thread_group threadGroup; + /// Flag indicating a restart + bool execute_restart; + /// Pass fatal exception message to UI thread void handleRunawayException(std::exception *e); }; @@ -262,6 +265,8 @@ void BitcoinCore::handleRunawayException(std::exception *e) void BitcoinCore::initialize() { + execute_restart = true; + try { qDebug() << __func__ << ": Running AppInit2 in thread"; @@ -282,23 +287,26 @@ void BitcoinCore::initialize() } void BitcoinCore::restart(QStringList args) -{ - try - { - qDebug() << __func__ << ": Running Restart in thread"; - threadGroup.interrupt_all(); - threadGroup.join_all(); - PrepareShutdown(); - qDebug() << __func__ << ": Shutdown finished"; - emit shutdownResult(1); - CExplicitNetCleanup::callCleanup(); - QProcess::startDetached(QApplication::applicationFilePath(), args); - qDebug() << __func__ << ": Restart initiated..."; - QCoreApplication::quit(); - } catch (std::exception& e) { - handleRunawayException(&e); - } catch (...) { - handleRunawayException(NULL); +{ + if(execute_restart) { // Only restart 1x, no matter how often a user clicks on a restart-button + execute_restart = false; + try + { + qDebug() << __func__ << ": Running Restart in thread"; + threadGroup.interrupt_all(); + threadGroup.join_all(); + PrepareShutdown(); + qDebug() << __func__ << ": Shutdown finished"; + emit shutdownResult(1); + CExplicitNetCleanup::callCleanup(); + QProcess::startDetached(QApplication::applicationFilePath(), args); + qDebug() << __func__ << ": Restart initiated..."; + QApplication::quit(); + } catch (std::exception& e) { + handleRunawayException(&e); + } catch (...) { + handleRunawayException(NULL); + } } }