From 5cf15b3f4e4b027827f5faf7348864247bd4c91b Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 28 Nov 2012 20:49:07 -0800 Subject: [PATCH] Shutdown cleanly on control-C. --- src/cpp/ripple/Application.cpp | 16 ++++++++++++++++ src/cpp/ripple/LedgerConsensus.cpp | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/src/cpp/ripple/Application.cpp b/src/cpp/ripple/Application.cpp index 7a4bfadef1..61b6005a2d 100644 --- a/src/cpp/ripple/Application.cpp +++ b/src/cpp/ripple/Application.cpp @@ -71,8 +71,24 @@ static void InitDB(DatabaseCon** dbCon, const char *fileName, const char *dbInit *dbCon = new DatabaseCon(fileName, dbInit, dbCount); } +volatile bool doShutdown = false; + +#ifdef SIGINT +void sigIntHandler(int) +{ + doShutdown = true; +} +#endif + 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); if (!theConfig.DEBUG_LOGFILE.empty()) { // Let DEBUG messages go to the file but only WARNING or higher to regular output (unless verbose) diff --git a/src/cpp/ripple/LedgerConsensus.cpp b/src/cpp/ripple/LedgerConsensus.cpp index e3e867d90a..7401461e86 100644 --- a/src/cpp/ripple/LedgerConsensus.cpp +++ b/src/cpp/ripple/LedgerConsensus.cpp @@ -644,8 +644,16 @@ void LedgerConsensus::stateAccepted() endConsensus(); } +extern volatile bool doShutdown; + void LedgerConsensus::timerEntry() { + if (doShutdown) + { + cLog(lsFATAL) << "Shutdown requested"; + theApp->stop(); + } + if ((mState != lcsFINISHED) && (mState != lcsACCEPTED)) checkLCL();