[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-1-0' - loolwsd/LOOLForKit.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sun May 29 16:08:02 UTC 2016


 loolwsd/LOOLForKit.cpp |   44 ++++++++++++++++++++++++++------------------
 1 file changed, 26 insertions(+), 18 deletions(-)

New commits:
commit 7f2fd2427098e431fcc45febbf0473b99281cef2
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Thu May 19 20:27:24 2016 -0400

    loolwsd: more frequent zombie reaping in forkit
    
    Change-Id: I10d859880cfd933c38572852f506eedf603e8fad
    Reviewed-on: https://gerrit.libreoffice.org/25232
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>
    (cherry picked from commit 6ce9868a9c3555a2aa848da53bbc1a14f642d468)
    Reviewed-on: https://gerrit.libreoffice.org/25615

diff --git a/loolwsd/LOOLForKit.cpp b/loolwsd/LOOLForKit.cpp
index f0e5dc3..4ff57cf 100644
--- a/loolwsd/LOOLForKit.cpp
+++ b/loolwsd/LOOLForKit.cpp
@@ -112,6 +112,26 @@ private:
     }
 };
 
+/// Check if some previously forked kids have died.
+static void cleanupChildren()
+{
+    Process::PID exitedChildPid;
+    int status;
+    while ((exitedChildPid = waitpid(-1, &status, WNOHANG)) > 0)
+    {
+        if (childJails.find(exitedChildPid) != childJails.end())
+        {
+            Log::info("Child " + std::to_string(exitedChildPid) + " has exited, removing its jail '" + childJails[exitedChildPid] + "'");
+            Util::removeFile(childJails[exitedChildPid], true);
+            childJails.erase(exitedChildPid);
+        }
+        else
+        {
+            Log::error("Unknown child " + std::to_string(exitedChildPid) + " has exited");
+        }
+    }
+}
+
 static int createLibreOfficeKit(const std::string& childRoot,
                                 const std::string& sysTemplate,
                                 const std::string& loTemplate,
@@ -142,26 +162,10 @@ static int createLibreOfficeKit(const std::string& childRoot,
     else
     {
         // Parent
-
-        // Check if some previously forked kids have died
-        Process::PID exitedChildPid;
-        int status;
-        while ((exitedChildPid = waitpid(-1, &status, WNOHANG)) > 0)
-        {
-            if (childJails.find(exitedChildPid) != childJails.end())
-            {
-                Log::info("Child " + std::to_string(exitedChildPid) + " has exited, removing its jail '" + childJails[exitedChildPid] + "'");
-                Util::removeFile(childJails[exitedChildPid], true);
-                childJails.erase(exitedChildPid);
-            }
-            else
-            {
-                Log::error("Unknown child " + std::to_string(exitedChildPid) + " has exited");
-            }
-        }
-
         if (pid < 0)
+        {
             Log::syserror("Fork failed.");
+        }
         else
         {
             Log::info("Forked kit [" + std::to_string(pid) + "].");
@@ -343,6 +347,10 @@ int main(int argc, char** argv)
             // If we need to spawn more, retry later.
             ForkCounter = (newInstances >= ForkCounter ? 0 : ForkCounter - newInstances);
         }
+        else
+        {
+            cleanupChildren();
+        }
     }
 
     close(pipeFd);


More information about the Libreoffice-commits mailing list