[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-7' - loolwsd/LOOLWSD.cpp loolwsd/Util.cpp loolwsd/Util.hpp

Henry Castro hcastro at collabora.com
Tue Feb 2 00:17:14 UTC 2016


 loolwsd/LOOLWSD.cpp |   21 ++++++++++++++++++--
 loolwsd/Util.cpp    |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 loolwsd/Util.hpp    |   17 ++++++++++++++++
 3 files changed, 89 insertions(+), 3 deletions(-)

New commits:
commit 78e19dbedc4f2257bdad63608a8f70e65b486e04
Author: Henry Castro <hcastro at collabora.com>
Date:   Mon Feb 1 20:14:26 2016 -0400

    loolwsd: avoid fork a new child when its exit code is not success

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index ca909aa..d8070e0 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1227,6 +1227,8 @@ bool LOOLWSD::startupComponent(int nComponents)
 
 void LOOLWSD::desktopMain()
 {
+    int nChildExitCode = Application::EXIT_OK;
+
 #ifdef __linux
     if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>("loolbroker"), 0, 0, 0) != 0)
         std::cout << Util::logPrefix() << "Cannot set thread name :" << strerror(errno) << std::endl;
@@ -1248,7 +1250,20 @@ void LOOLWSD::desktopMain()
             {
                 if ((WIFEXITED(status) || WIFSIGNALED(status)))
                 {
-                    std::cout << Util::logPrefix() << "One of our known child processes died :" << std::to_string(pid)  << std::endl;
+                    if (WIFEXITED(status))
+                    {
+                        nChildExitCode = Util::getChildStatus(WEXITSTATUS(status));
+                        std::cout << Util::logPrefix() << "One of our known child processes died :" << std::to_string(pid)
+                                  << " exit code " << std::to_string(WEXITSTATUS(status)) << std::endl;
+                    }
+                    else
+                    if (WIFSIGNALED(status))
+                    {
+                        nChildExitCode = Util::getSignalStatus(WTERMSIG(status));
+                        std::cout << Util::logPrefix() << "One of our known child processes died :" << std::to_string(pid)
+                                  << " signal code " << strsignal(WTERMSIG(status)) << std::endl;
+                    }
+
                     // remove chroot child
                     File aWorkSpace(LOOLWSD::childRoot + Path::separator() +
                                     std::to_string(MasterProcessSession::_childProcesses[pid]));
@@ -1256,6 +1271,7 @@ void LOOLWSD::desktopMain()
                         aWorkSpace.remove(true);
 
                     MasterProcessSession::_childProcesses.erase(pid);
+                    timeoutCounter = -1;
                 }
 
                 if ( WCOREDUMP(status) )
@@ -1289,7 +1305,7 @@ void LOOLWSD::desktopMain()
             if (MasterProcessSession::_childProcesses.size() + toSpawn < _numPreSpawnedChildren)
                 toSpawn = _numPreSpawnedChildren - MasterProcessSession::_childProcesses.size();
 
-            if (toSpawn > 0)
+            if (toSpawn > 0 && nChildExitCode == Application::EXIT_OK)
             {
                 std::cout << Util::logPrefix() << "Create child session, fork new ones: " << toSpawn << std::endl;
                 if (!startupComponent(toSpawn))
@@ -1302,6 +1318,7 @@ void LOOLWSD::desktopMain()
         {
             timeoutCounter = 0;
             sleep(MAINTENANCE_INTERVAL);
+            nChildExitCode = Application::EXIT_OK;
         }
     }
 
diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp
index faf7518..7980fbd 100644
--- a/loolwsd/Util.cpp
+++ b/loolwsd/Util.cpp
@@ -84,7 +84,7 @@ namespace Util
 
     bool encodeBufferToPNG(unsigned char *pixmap, int width, int height, std::vector<char>& output, LibreOfficeKitTileMode mode)
     {
-       
+
         return encodeSubBufferToPNG(pixmap, 0, 0, width, height, width, height, output, mode);
     }
 
@@ -200,6 +200,58 @@ namespace Util
             return std::to_string(signo);
         }
     }
+
+    int getChildStatus(const int nCode)
+    {
+        int nRetVal;
+
+        switch (static_cast<const LOOLExitCode>(nCode))
+        {
+            case LOOLExitCode::LOOL_SECOND_OFFICE:
+            case LOOLExitCode::LOOL_FATAL_ERROR:
+            case LOOLExitCode::LOOL_CRASH_WITH_RESTART:
+            case LOOLExitCode::LOOL_NORMAL_RESTART:
+            case LOOLExitCode::LOOL_EXIT_SOFTWARE:
+                nRetVal = EXIT_FAILURE;
+            break;
+
+            case LOOLExitCode::LOOL_NO_ERROR:
+                nRetVal = EXIT_SUCCESS;
+            break;
+
+            default:
+                nRetVal = EXIT_SUCCESS;
+            break;
+        }
+
+        return nRetVal;
+    }
+
+    int getSignalStatus(const int nCode)
+    {
+        int nRetVal;
+
+        switch (nCode)
+        {
+            case SIGSEGV:
+            case SIGBUS:
+            case SIGABRT:
+            case SIGILL:
+            case SIGFPE:
+            case SIGTERM:
+            case SIGINT:
+            case SIGQUIT:
+            case SIGHUP:
+                nRetVal = EXIT_FAILURE;
+            break;
+
+            default:
+                nRetVal = EXIT_SUCCESS;
+            break;
+        }
+
+        return nRetVal;
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index e4f3d55..ff95802 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -17,6 +17,21 @@
 #define LOK_USE_UNSTABLE_API
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 
+enum class LOOLExitCode
+{
+    LOOL_NO_ERROR = 0,
+    /* pipe was detected - second office must terminate itself */
+    LOOL_SECOND_OFFICE = 1,
+    /* an uno exception was catched during startup */
+    LOOL_FATAL_ERROR = 77, /* Only the low 8 bits are significant 333 % 256 = 77 */
+    /* user force automatic restart after crash */
+    LOOL_CRASH_WITH_RESTART = 79,
+    /* the office restarts itself */
+    LOOL_NORMAL_RESTART = 81,
+    /* internal software error */
+    LOOL_EXIT_SOFTWARE = 70
+};
+
 namespace Util
 {
     std::string logPrefix();
@@ -35,6 +50,8 @@ namespace Util
     void shutdownWebSocket(Poco::Net::WebSocket& ws);
 
     std::string signalName(int signo);
+    int getChildStatus(const int nCode);
+    int getSignalStatus(const int nCode);
 };
 
 #endif


More information about the Libreoffice-commits mailing list