[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/Util.cpp loolwsd/Util.hpp

Henry Castro hcastro at collabora.com
Tue Feb 2 01:26:47 UTC 2016


 loolwsd/LOOLBroker.cpp |    3 +-
 loolwsd/LOOLKit.cpp    |    3 +-
 loolwsd/LOOLWSD.cpp    |    3 +-
 loolwsd/Util.cpp       |   60 +++++++++++++++++++++++++++++++++++++------------
 loolwsd/Util.hpp       |    3 +-
 5 files changed, 54 insertions(+), 18 deletions(-)

New commits:
commit b477f4163619e52e3a46e681612c0afbf28a2acf
Author: Henry Castro <hcastro at collabora.com>
Date:   Mon Feb 1 21:26:19 2016 -0400

    loolwsd: add fatal signals handler

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index f58a4f3..cb93536 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -669,7 +669,8 @@ int main(int argc, char** argv)
     // Initialization
     Log::initialize("brk");
 
-    Util::setSignals(false);
+    Util::setTerminationSignals();
+    Util::setFatalSignals();
 
     std::string childRoot;
     std::string jailId;
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 04e5d82..ec3e7b3 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -517,7 +517,8 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s
 #ifdef __linux
     if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(process_name.c_str()), 0, 0, 0) != 0)
         Log::error("Cannot set process name to " + process_name + ".");
-    Util::setSignals(false);
+    Util::setTerminationSignals();
+    Util::setFatalSignals();
 #endif
     Log::debug("Process [" + process_name + "] started.");
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index b5ef7e0..2e59e0e 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -896,7 +896,8 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
         setlocale(LC_ALL, "en_US.utf8");
 #endif
 
-    Util::setSignals(false);
+    Util::setTerminationSignals();
+    Util::setFatalSignals();
 
     if (access(Cache.c_str(), R_OK | W_OK | X_OK) != 0)
     {
diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp
index ee2b5d1..088620c 100644
--- a/loolwsd/Util.cpp
+++ b/loolwsd/Util.cpp
@@ -416,7 +416,7 @@ namespace Util
     }
 
     static
-    void handleSignal(int aSignal)
+    void handleTerminationSignal(const int aSignal)
     {
         if (!TerminationFlag)
         {
@@ -426,37 +426,69 @@ namespace Util
             TerminationFlag = true;
             TerminationState = ( aSignal == SIGTERM ? LOOLState::LOOL_ABNORMAL : LOOLState::LOOL_STOPPING );
 
-            Log::info() << "Signal received: " << strsignal(aSignal) << Log::end;
-            if (aSignal == SIGSEGV || aSignal == SIGBUS)
-            {
-                Log::error() << "\nSegfault! Attach debugger with:\n"
-                             << "sudo gdb --pid=" << Poco::Process::id() << "\n or \n"
-                             << "sudo gdb --q --n --ex 'thread apply all backtrace full' --batch --pid="
-                             << Poco::Process::id() << "\n" << Log::end;
-                sleep(10);
-            }
+            Log::info() << "Termination signal received: "
+                        << strsignal(aSignal) << Log::end;
         }
     }
 
-    void setSignals(bool isIgnored)
+    void setTerminationSignals()
     {
 #ifdef __linux
         struct sigaction aSigAction;
 
         sigemptyset(&aSigAction.sa_mask);
         aSigAction.sa_flags = 0;
-        aSigAction.sa_handler = (isIgnored ? SIG_IGN : handleSignal);
+        aSigAction.sa_handler = handleTerminationSignal;
 
         sigaction(SIGTERM, &aSigAction, nullptr);
         sigaction(SIGINT, &aSigAction, nullptr);
         sigaction(SIGQUIT, &aSigAction, nullptr);
         sigaction(SIGHUP, &aSigAction, nullptr);
+#endif
+    }
+
+    static
+    void handleFatalSignal(const int aSignal)
+    {
+        Log::error() << "Fatal signal received: "
+                     << strsignal(aSignal) << Log::end;
 
         if (getenv("LOOL_DEBUG"))
         {
-            sigaction(SIGBUS, &aSigAction, nullptr);
-            sigaction(SIGSEGV, &aSigAction, nullptr);
+            Log::error() << "\nSegfault! Attach debugger with:\n"
+                         << "sudo gdb --pid=" << Poco::Process::id() << "\n or \n"
+                         << "sudo gdb --q --n --ex 'thread apply all backtrace full' --batch --pid="
+                         << Poco::Process::id() << "\n" << Log::end;
+            sleep(10);
         }
+
+#ifdef __linux
+        struct sigaction aSigAction;
+
+        sigemptyset(&aSigAction.sa_mask);
+        aSigAction.sa_flags = 0;
+        aSigAction.sa_handler = SIG_DFL;
+
+        sigaction(aSignal, &aSigAction, NULL);
+        // let default handler process the signal
+        kill(Poco::Process::id(), aSignal);
+#endif
+    }
+
+    void setFatalSignals()
+    {
+#ifdef __linux
+        struct sigaction aSigAction;
+
+        sigemptyset(&aSigAction.sa_mask);
+        aSigAction.sa_flags = 0;
+        aSigAction.sa_handler = handleFatalSignal;
+
+        sigaction(SIGSEGV, &aSigAction, NULL);
+        sigaction(SIGBUS, &aSigAction, NULL);
+        sigaction(SIGABRT, &aSigAction, NULL);
+        sigaction(SIGILL, &aSigAction, NULL);
+        sigaction(SIGFPE, &aSigAction, NULL);
 #endif
     }
 }
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index 2f74c28..b599508 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -98,7 +98,8 @@ namespace Util
     std::string signalName(int signo);
 
     /// Trap signals to cleanup and exit the process gracefully.
-    void setSignals(bool isIgnored);
+    void setTerminationSignals();
+    void setFatalSignals();
 };
 
 //TODO: Move to own file.


More information about the Libreoffice-commits mailing list