Shutdown cleanly on control-C.

This commit is contained in:
JoelKatz
2012-11-28 20:49:07 -08:00
parent 72777b6b83
commit 5cf15b3f4e
2 changed files with 24 additions and 0 deletions

View File

@@ -71,8 +71,24 @@ static void InitDB(DatabaseCon** dbCon, const char *fileName, const char *dbInit
*dbCon = new DatabaseCon(fileName, dbInit, dbCount); *dbCon = new DatabaseCon(fileName, dbInit, dbCount);
} }
volatile bool doShutdown = false;
#ifdef SIGINT
void sigIntHandler(int)
{
doShutdown = true;
}
#endif
void Application::run() void Application::run()
{ {
#ifdef SIGINT
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = sigIntHandler;
sigaction(SIGINT, &sa, NULL);
#endif
assert(mTxnDB == NULL); assert(mTxnDB == NULL);
if (!theConfig.DEBUG_LOGFILE.empty()) if (!theConfig.DEBUG_LOGFILE.empty())
{ // Let DEBUG messages go to the file but only WARNING or higher to regular output (unless verbose) { // Let DEBUG messages go to the file but only WARNING or higher to regular output (unless verbose)

View File

@@ -644,8 +644,16 @@ void LedgerConsensus::stateAccepted()
endConsensus(); endConsensus();
} }
extern volatile bool doShutdown;
void LedgerConsensus::timerEntry() void LedgerConsensus::timerEntry()
{ {
if (doShutdown)
{
cLog(lsFATAL) << "Shutdown requested";
theApp->stop();
}
if ((mState != lcsFINISHED) && (mState != lcsACCEPTED)) if ((mState != lcsFINISHED) && (mState != lcsACCEPTED))
checkLCL(); checkLCL();