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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Jan 4 17:14:46 PST 2016


 loolwsd/LOOLBroker.cpp |   39 +++++++++++++++++++++------------------
 loolwsd/LOOLKit.cpp    |    9 +++++++--
 2 files changed, 28 insertions(+), 20 deletions(-)

New commits:
commit fa2eccacfadec2e832ba8755eaefbdec076b84f1
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Mon Jan 4 16:53:11 2016 -0500

    loolwsd: fix page sharing between broker and lokit (aka forking)
    
    Change-Id: I870d0291925e718e038f42b21d00ea744133db01
    Reviewed-on: https://gerrit.libreoffice.org/21098
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 2c4c819..a02cc72 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -448,6 +448,14 @@ static int createLibreOfficeKit(const bool sharePages, const std::string& loSubP
     Poco::UInt64 child;
     int nFIFOWriter = -1;
 
+    const std::string pipe = BROKER_PREFIX + std::to_string(childCounter++) + BROKER_SUFIX;
+
+    if (mkfifo(pipe.c_str(), 0666) < 0)
+    {
+        Log::error("Error: mkfifo failed.");
+        return -1;
+    }
+
     if (sharePages)
     {
         Log::debug("Forking LibreOfficeKit.");
@@ -456,25 +464,18 @@ static int createLibreOfficeKit(const bool sharePages, const std::string& loSubP
         if (!(pid = fork()))
         {
             // child
-            run_lok_main(loSubPath, childId, childId);
+            lokit_main(loSubPath, childId, pipe);
             _exit(0);
         }
         else
         {
             // parent
             child = pid; // (somehow - switch the hash to use real pids or ?) ...
+            Log::info("Forked kit [" + std::to_string(child) + "].");
         }
     }
     else
     {
-        const std::string pipe = BROKER_PREFIX + std::to_string(childCounter++) + BROKER_SUFIX;
-
-        if (mkfifo(pipe.c_str(), 0666) < 0)
-        {
-            Log::error("Error: mkfifo failed.");
-            return -1;
-        }
-
         Process::Args args;
         args.push_back("--losubpath=" + loSubPath);
         args.push_back("--child=" + childId);
@@ -487,21 +488,23 @@ static int createLibreOfficeKit(const bool sharePages, const std::string& loSubP
 
         ProcessHandle procChild = Process::launch(JAILED_LOOLKIT_PATH, args);
         child = procChild.id();
+        Log::info("Spawned kit [" + std::to_string(child) + "].");
+
         if (!Process::isRunning(procChild))
         {
             // This can happen if we fail to copy it, or bad chroot etc.
-            Log::error("Error: loolkit was stillborn.");
+            Log::error("Error: loolkit [" + std::to_string(child) + "] was stillborn.");
             return -1;
         }
+    }
 
-        if ( (nFIFOWriter = open(pipe.c_str(), O_WRONLY)) < 0 )
-        {
-            // TODO.  ill process state, that state should force close prison websockets and
-            // kill, currently we have only "stop server state".
-            Log::error("Error: failed to open pipe [" + pipe + "] write only. Abandoning child.");
-            Poco::Process::requestTermination(child);
-            return -1;
-        }
+    if ( (nFIFOWriter = open(pipe.c_str(), O_WRONLY)) < 0 )
+    {
+        // TODO.  ill process state, that state should force close prison websockets and
+        // kill, currently we have only "stop server state".
+        Log::error("Error: failed to open write pipe [" + pipe + "] with kit. Abandoning child.");
+        Poco::Process::requestTermination(child);
+        return -1;
     }
 
     Log::info() << "Adding Kit #" << childCounter << " PID " << child << Log::end;
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index a1917e5..04d5e80 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -632,8 +632,13 @@ private:
     std::map<std::string, std::shared_ptr<Connection>> _connections;
 };
 
-void run_lok_main(const std::string &loSubPath, const std::string& childId, const std::string& pipe)
+void lokit_main(const std::string &loSubPath, const std::string& childId, const std::string& pipe)
 {
+#ifdef LOOLKIT_NO_MAIN
+    // Reinitialize logging when forked.
+    Log::initialize("kit");
+#endif
+
     struct pollfd aPoll;
     ssize_t nBytes = -1;
     char  aBuffer[PIPE_BUFFER];
@@ -890,7 +895,7 @@ int main(int argc, char** argv)
         Log::error(std::string("Exception: ") + exc.what());
     }
 
-    run_lok_main(loSubPath, childId, pipe);
+    lokit_main(loSubPath, childId, pipe);
 
     return 0;
 }


More information about the Libreoffice-commits mailing list