changeset 2009:e2dd40abce72

catching SIGHUP signal
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 09 Jun 2016 17:25:34 +0200
parents dc82c754dcaa
children 4dafe2a0d3ab
files Core/Toolbox.cpp Core/Toolbox.h OrthancServer/main.cpp Plugins/Engine/OrthancPlugins.cpp
diffstat 4 files changed, 40 insertions(+), 15 deletions(-) [+]
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);
   }
 
 
--- 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
 
--- 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
--- 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<ImageAccessor*>(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";
       }
     }