# HG changeset patch # User Sebastien Jodogne # Date 1465485934 -7200 # Node ID e2dd40abce72dc98024a34d790baba2c50a79f87 # Parent dc82c754dcaad7ba8878831cd8a4725b03cb566a catching SIGHUP signal diff -r dc82c754dcaa -r e2dd40abce72 Core/Toolbox.cpp --- 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); } diff -r dc82c754dcaa -r e2dd40abce72 Core/Toolbox.h --- a/Core/Toolbox.h Thu Jun 09 15:51:46 2016 +0200 +++ b/Core/Toolbox.h Thu Jun 09 17:25:34 2016 +0200 @@ -47,11 +47,17 @@ { }; + enum ServerBarrierEvent + { + ServerBarrierEvent_Stop, + ServerBarrierEvent_Reload // SIGHUP signal: reload configuration file + }; + namespace Toolbox { - void ServerBarrier(const bool& stopFlag); + ServerBarrierEvent ServerBarrier(const bool& stopFlag); - void ServerBarrier(); + ServerBarrierEvent ServerBarrier(); void ToUpperCase(std::string& s); // Inplace version diff -r dc82c754dcaa -r e2dd40abce72 OrthancServer/main.cpp --- a/OrthancServer/main.cpp Thu Jun 09 15:51:46 2016 +0200 +++ b/OrthancServer/main.cpp Thu Jun 09 17:25:34 2016 +0200 @@ -651,9 +651,16 @@ context.GetLua().Execute("Initialize"); - Toolbox::ServerBarrier(restApi.LeaveBarrierFlag()); + ServerBarrierEvent event = Toolbox::ServerBarrier(restApi.LeaveBarrierFlag()); bool restart = restApi.IsResetRequestReceived(); + if (!restart && + event == ServerBarrierEvent_Reload) + { + printf("RECEIVED SIGHUP\n"); + } + + context.GetLua().Execute("Finalize"); #if ORTHANC_PLUGINS_ENABLED == 1 diff -r dc82c754dcaa -r e2dd40abce72 Plugins/Engine/OrthancPlugins.cpp --- a/Plugins/Engine/OrthancPlugins.cpp Thu Jun 09 15:51:46 2016 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Thu Jun 09 17:25:34 2016 +0200 @@ -2987,7 +2987,7 @@ return reinterpret_cast(pluginImage); } - LOG(WARNING) << "The custom image decoder cannot handle an image, fallback to the built-in decoder"; + LOG(INFO) << "The installed image decoding plugins cannot handle an image, fallback to the built-in decoder"; } }