Mercurial > hg > orthanc
diff Core/Toolbox.cpp @ 2009:e2dd40abce72
catching SIGHUP signal
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 09 Jun 2016 17:25:34 +0200 |
parents | e29aea2349b9 |
children | 4dafe2a0d3ab |
line wrap: on
line diff
--- a/Core/Toolbox.cpp Thu Jun 09 15:51:46 2016 +0200 +++ b/Core/Toolbox.cpp Thu Jun 09 17:25:34 2016 +0200 @@ -111,19 +111,26 @@ namespace Orthanc { - static bool finish; + static bool finish_; + static ServerBarrierEvent barrierEvent_; #if defined(_WIN32) static BOOL WINAPI ConsoleControlHandler(DWORD dwCtrlType) { // http://msdn.microsoft.com/en-us/library/ms683242(v=vs.85).aspx - finish = true; + finish_ = true; + barrierEvent_ = ServerBarrierEvent_Stop; return true; } #else - static void SignalHandler(int) + static void SignalHandler(int signal) { - finish = true; + if (signal == SIGHUP) + { + barrierEvent_ = ServerBarrierEvent_Reload; + } + + finish_ = true; } #endif @@ -140,7 +147,7 @@ } - static void ServerBarrierInternal(const bool* stopFlag) + static ServerBarrierEvent ServerBarrierInternal(const bool* stopFlag) { #if defined(_WIN32) SetConsoleCtrlHandler(ConsoleControlHandler, true); @@ -148,11 +155,13 @@ signal(SIGINT, SignalHandler); signal(SIGQUIT, SignalHandler); signal(SIGTERM, SignalHandler); + signal(SIGHUP, SignalHandler); #endif // Active loop that awakens every 100ms - finish = false; - while (!(*stopFlag || finish)) + finish_ = false; + barrierEvent_ = ServerBarrierEvent_Stop; + while (!(*stopFlag || finish_)) { Toolbox::USleep(100 * 1000); } @@ -163,19 +172,22 @@ signal(SIGINT, NULL); signal(SIGQUIT, NULL); signal(SIGTERM, NULL); + signal(SIGHUP, NULL); #endif + + return barrierEvent_; } - void Toolbox::ServerBarrier(const bool& stopFlag) + ServerBarrierEvent Toolbox::ServerBarrier(const bool& stopFlag) { - ServerBarrierInternal(&stopFlag); + return ServerBarrierInternal(&stopFlag); } - void Toolbox::ServerBarrier() + ServerBarrierEvent Toolbox::ServerBarrier() { const bool stopFlag = false; - ServerBarrierInternal(&stopFlag); + return ServerBarrierInternal(&stopFlag); }