From b1664bb184618ce1d72290ac8e17f9da5d99bedc Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Fri, 10 Sep 2021 13:24:15 +0300 Subject: [PATCH] Application: Perform hard-shutdown after 3 Ctrl+C's --- src/Common.cpp | 11 +++++++++-- src/main.cpp | 3 +-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Common.cpp b/src/Common.cpp index f7875c6..478cc8f 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -22,10 +22,17 @@ void Application::RegisterShutdownHandler(const TShutdownHandler& Handler) { } } -static bool AlreadyShuttingDown = false; void Application::GracefullyShutdown() { + static bool AlreadyShuttingDown = false; + static uint8_t ShutdownAttempts = 0; if (AlreadyShuttingDown) { - info("already shutting down"); + ++ShutdownAttempts; + // hard shutdown at 2 additional tries + if (ShutdownAttempts == 2) { + info("hard shutdown forced by multiple shutdown requests"); + exit(0); + } + info("already shutting down!"); return; } else { AlreadyShuttingDown = true; diff --git a/src/main.cpp b/src/main.cpp index 9f5b339..01a77ae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,7 @@ #include "Common.h" #include "CustomAssert.h" #include "Http.h" +#include "SignalHandling.h" #include "TConfig.h" #include "THeartbeatThread.h" #include "TLuaEngine.h" @@ -10,7 +11,6 @@ #include "TPPSMonitor.h" #include "TResourceManager.h" #include "TServer.h" -#include "SignalHandling.h" #include #include @@ -63,4 +63,3 @@ int main(int argc, char** argv) try { error(e.what()); Sentry.LogException(e, _file_basename, _line); } -