Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 25 additions & 17 deletions src/qt/dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -262,6 +265,8 @@ void BitcoinCore::handleRunawayException(std::exception *e)

void BitcoinCore::initialize()
{
execute_restart = true;

try
{
qDebug() << __func__ << ": Running AppInit2 in thread";
Expand All @@ -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);
}
}
}

Expand Down