[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Thu Nov 10 05:17:36 UTC 2016


 loolwsd/LOOLWSD.cpp |   48 ++++++++++++++++++++++++++++++------------------
 1 file changed, 30 insertions(+), 18 deletions(-)

New commits:
commit 8b5f112ebf56cc63ada0fe02c66d31dc10f7c439
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Wed Nov 9 23:41:21 2016 -0500

    loolwsd: recover when forkit dies
    
    Change-Id: Idc1e08fb496d3c68b22e1d8eab2da9a9064ef070
    Reviewed-on: https://gerrit.libreoffice.org/30743
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 4c9ed10..40876de 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1834,7 +1834,15 @@ Process::PID LOOLWSD::createForKit()
     // The Pipe dtor closes the fd, so dup it.
     ForKitWritePipe = dup(inPipe.writeHandle());
 
-    return child.id();
+    const auto forkitPid = child.id();
+
+    // Init the Admin manager
+    Admin::instance().setForKitPid(forkitPid);
+
+    // Spawn some children, if necessary.
+    preForkChildren();
+
+    return forkitPid;
 }
 
 int LOOLWSD::main(const std::vector<std::string>& /*args*/)
@@ -1925,19 +1933,13 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
     srv2.start();
 
     // Fire the ForKit process; we are ready to get child connections.
-    const Process::PID forKitPid = createForKit();
+    Process::PID forKitPid = createForKit();
     if (forKitPid < 0)
     {
         LOG_FTL("Failed to spawn loolforkit.");
         return Application::EXIT_SOFTWARE;
     }
 
-    // Init the Admin manager
-    Admin::instance().setForKitPid(forKitPid);
-
-    // Spawn some children, if necessary.
-    preForkChildren();
-
     // Now we can serve clients; Start listening on the public port.
     std::unique_ptr<ServerSocket> psvs(
         UnitWSD::isUnitTesting() ?
@@ -1967,17 +1969,27 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
         {
             if (forKitPid == pid)
             {
-                if (WIFEXITED(status) == true)
+                if (WIFEXITED(status) || WIFSIGNALED(status))
                 {
-                    LOG_INF("Child process [" << pid << "] exited with code: " << WEXITSTATUS(status) << ".");
-                    break;
-                }
-                else if (WIFSIGNALED(status) == true)
-                {
-                    const auto fate = (WCOREDUMP(status) ? "core-dumped" : "died");
-                    LOG_ERR("Child process [" << pid << "] " << fate <<
-                            " with " << Util::signalName(WTERMSIG(status)));
-                    break;
+                    if (WIFEXITED(status))
+                    {
+                        LOG_INF("Child process [" << pid << "] exited with code: " <<
+                                WEXITSTATUS(status) << ".");
+                    }
+                    else
+                    {
+                        LOG_ERR("Child process [" << pid << "] " <<
+                                (WCOREDUMP(status) ? "core-dumped" : "died") <<
+                                " with " << Util::signalName(WTERMSIG(status)));
+                    }
+
+                    // Spawn a new forkit and try to dust it off and resume.
+                    forKitPid = createForKit();
+                    if (forKitPid < 0)
+                    {
+                        LOG_FTL("Failed to spawn forkit instance. Shutting down.");
+                        break;
+                    }
                 }
                 else if (WIFSTOPPED(status) == true)
                 {


More information about the Libreoffice-commits mailing list