[Libreoffice-commits] online.git: kit/ForKit.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Jan 9 06:21:47 UTC 2017


 kit/ForKit.cpp |   29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

New commits:
commit f242865c3df107ae1de4d0ed4358871b07b719d1
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Jan 8 15:17:47 2017 -0500

    wsd: simplify kit forking
    
    Change-Id: I49338fbd2ccf944493f94a8f2c98750711733f1a
    Reviewed-on: https://gerrit.libreoffice.org/32865
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/kit/ForKit.cpp b/kit/ForKit.cpp
index f0fe536..ba3d548 100644
--- a/kit/ForKit.cpp
+++ b/kit/ForKit.cpp
@@ -207,8 +207,8 @@ static int createLibreOfficeKit(const std::string& childRoot,
 {
     LOG_DBG("Forking a loolkit process.");
 
-    Process::PID pid;
-    if (!(pid = fork()))
+    const Process::PID pid = fork();
+    if (!pid)
     {
         // Child
 
@@ -412,31 +412,24 @@ int main(int argc, char** argv)
             break;
         }
 
+        // Cleanup first, to reduce disk load.
+        cleanupChildren();
+
         if (ForkCounter > 0)
         {
             // Create as many as requested.
-            int spawn = ForkCounter;
-            LOG_INF("Creating " << spawn << " new child.");
-            size_t newInstances = 0;
-            do
+            const size_t count = ForkCounter;
+            LOG_INF("Spawning " << count << " new child" << (count == 1 ? "." : "ren."));
+            const size_t retry = count * 2;
+            for (size_t i = 0; ForkCounter > 0 && i < retry; ++i)
             {
-                if (createLibreOfficeKit(childRoot, sysTemplate, loTemplate, loSubPath) < 0)
+                if (ForkCounter-- <= 0 || createLibreOfficeKit(childRoot, sysTemplate, loTemplate, loSubPath) < 0)
                 {
                     LOG_ERR("Failed to create a kit process.");
-                }
-                else
-                {
-                    ++newInstances;
+                    ++ForkCounter;
                 }
             }
-            while (--spawn > 0);
-
-            // If we need to spawn more, retry later.
-            ForkCounter = (newInstances >= ForkCounter ? 0 : ForkCounter - newInstances);
         }
-
-        // We virtually always fork when a child exits.
-        cleanupChildren();
     }
 
     int returnValue = Application::EXIT_OK;


More information about the Libreoffice-commits mailing list