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

Tor Lillqvist tml at collabora.com
Mon Feb 15 20:59:56 UTC 2016


 loolwsd/LOOLBroker.cpp |   44 ++++++++++++++++++++++++++++++++------------
 1 file changed, 32 insertions(+), 12 deletions(-)

New commits:
commit b276c3541c4d569fab25e5dbe91a93eca7d89bf6
Author: Tor Lillqvist <tml at collabora.com>
Date:   Mon Feb 15 22:32:51 2016 +0200

    Probably we should pass loTemplate to globalPreinit(), not loSubPath
    
    globalPreinit() does not run in a chroot as far as I see, so trying to
    use loSubPath as an absolute path will not work. Probably what was
    meant is loTemplate, then the libraries at least are found.

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 4291d69..22ae676 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -431,12 +431,12 @@ private:
 };
 
 /// Initializes LibreOfficeKit for cross-fork re-use.
-static bool globalPreinit(const std::string &loSubPath)
+static bool globalPreinit(const std::string &loTemplate)
 {
     void *handle;
     LokHookPreInit* preInit;
 
-    std::string libSofficeapp = "/" + loSubPath + "/program/" LIB_SOFFICEAPP;
+    std::string libSofficeapp = loTemplate + "/program/" LIB_SOFFICEAPP;
     std::string loadedLibrary;
     if (File(libSofficeapp).exists())
     {
@@ -450,7 +450,7 @@ static bool globalPreinit(const std::string &loSubPath)
     }
     else
     {
-        std::string libMerged = "/" + loSubPath + "/program/" LIB_MERGED;
+        std::string libMerged = loTemplate + "/program/" LIB_MERGED;
         if (File(libMerged).exists())
         {
             handle = dlopen(libMerged.c_str(), RTLD_GLOBAL|RTLD_NOW);
@@ -475,7 +475,7 @@ static bool globalPreinit(const std::string &loSubPath)
         return false;
     }
 
-    return preInit(("/" + loSubPath + "/program").c_str(), "file:///user") == 0;
+    return preInit((loTemplate + "/program").c_str(), "file:///user") == 0;
 }
 
 static int createLibreOfficeKit(const bool sharePages,
@@ -765,7 +765,7 @@ int main(int argc, char** argv)
     }
 
     // Initialize LoKit and hope we can fork and save memory by sharing pages.
-    const bool sharePages = globalPreinit(loSubPath);
+    const bool sharePages = globalPreinit(loTemplate);
 
     if (!sharePages)
         Log::warn("Cannot fork, will spawn instead.");
commit c62d612562c44fc18994949453008559b8451c99
Author: Tor Lillqvist <tml at collabora.com>
Date:   Mon Feb 15 17:18:12 2016 +0200

    Clean up error reporing
    
    If neither libsofficeapp.so or libmerged.so exist where we look for
    them, say so explicitly.
    
    Log the error message from dlerror(), too.
    
    Log the mesage about not forking in all cases when doing that, not
    just if lok_preinit is not found.
    
    Execing is not an alternative to fork(), spawning is.

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 5d81486..4291d69 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -436,16 +436,34 @@ static bool globalPreinit(const std::string &loSubPath)
     void *handle;
     LokHookPreInit* preInit;
 
-    std::string fname = "/" + loSubPath + "/program/" LIB_SOFFICEAPP;
-    handle = dlopen(fname.c_str(), RTLD_GLOBAL|RTLD_NOW);
-    if (!handle)
+    std::string libSofficeapp = "/" + loSubPath + "/program/" LIB_SOFFICEAPP;
+    std::string loadedLibrary;
+    if (File(libSofficeapp).exists())
     {
-        Log::warn("Failed to load " + std::string(LIB_SOFFICEAPP) + " library. Trying " + std::string(LIB_MERGED));
-        fname = "/" + loSubPath + "/program/" LIB_MERGED;
-        handle = dlopen(fname.c_str(), RTLD_GLOBAL|RTLD_NOW);
+        handle = dlopen(libSofficeapp.c_str(), RTLD_GLOBAL|RTLD_NOW);
         if (!handle)
         {
-            Log::warn("Failed to load " + std::string(LIB_MERGED) + " library.");
+            Log::warn("Failed to load " + libSofficeapp + ": " + std::string(dlerror()));
+            return false;
+        }
+        loadedLibrary = libSofficeapp;
+    }
+    else
+    {
+        std::string libMerged = "/" + loSubPath + "/program/" LIB_MERGED;
+        if (File(libMerged).exists())
+        {
+            handle = dlopen(libMerged.c_str(), RTLD_GLOBAL|RTLD_NOW);
+            if (!handle)
+            {
+                Log::warn("Failed to load " + libMerged + ": " + std::string(dlerror()));
+                return false;
+            }
+            loadedLibrary = libMerged;
+        }
+        else
+        {
+            Log::warn("Neither " + libSofficeapp + " or " + libMerged + " exist.");
             return false;
         }
     }
@@ -453,8 +471,7 @@ static bool globalPreinit(const std::string &loSubPath)
     preInit = (LokHookPreInit *)dlsym(handle, "lok_preinit");
     if (!preInit)
     {
-        Log::warn("Note: No lok_preinit hook in " + std::string(LIB_SOFFICEAPP) +
-                  " library. Cannot fork, will execv instead.");
+        Log::warn("Note: No lok_preinit hook in " + loadedLibrary);
         return false;
     }
 
@@ -750,6 +767,9 @@ int main(int argc, char** argv)
     // Initialize LoKit and hope we can fork and save memory by sharing pages.
     const bool sharePages = globalPreinit(loSubPath);
 
+    if (!sharePages)
+        Log::warn("Cannot fork, will spawn instead.");
+
     // We must have at least one child, more is created dynamically.
     if (createLibreOfficeKit(sharePages, childRoot, sysTemplate,
                              loTemplate, loSubPath) < 0)


More information about the Libreoffice-commits mailing list