[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-1' - common/Protocol.hpp kit/ForKit.cpp wsd/LOOLWSD.cpp wsd/LOOLWSD.hpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Jul 31 20:56:18 UTC 2017


 common/Protocol.hpp |   15 +++++++++++++++
 kit/ForKit.cpp      |   16 ++++++++++++++++
 wsd/LOOLWSD.cpp     |    8 ++++++++
 wsd/LOOLWSD.hpp     |    2 +-
 4 files changed, 40 insertions(+), 1 deletion(-)

New commits:
commit 977d88e089d1cb382c52b776b7559b30bbe43db0
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Jun 11 11:48:24 2017 -0400

    wsd: pass default rlimits to forkit from config
    
    Change-Id: I84d271f460f0fb1d03a973107c32265d84bf2841
    Reviewed-on: https://gerrit.libreoffice.org/38675
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>
    (cherry picked from commit 6de3adcf9ce385152412a7a062245cb751a69cb6)
    Reviewed-on: https://gerrit.libreoffice.org/38760
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/common/Protocol.hpp b/common/Protocol.hpp
index cae54d46..e26703d5 100644
--- a/common/Protocol.hpp
+++ b/common/Protocol.hpp
@@ -161,6 +161,21 @@ namespace LOOLProtocol
         return std::string(message, size);
     }
 
+    /// Split a string in two at the delimeter, removing it.
+    inline
+    std::pair<std::string, std::string> split(const char* s, const int length, const char delimeter = ' ')
+    {
+        const auto size = getDelimiterPosition(s, length, delimeter);
+        return std::make_pair(std::string(s, size), std::string(s+size+1));
+    }
+
+    /// Split a string in two at the delimeter, removing it.
+    inline
+    std::pair<std::string, std::string> split(const std::string& s, const char delimeter = ' ')
+    {
+        return split(s.c_str(), s.size(), delimeter);
+    }
+
     /// Returns the first token of a message.
     inline
     std::string getFirstToken(const char *message, const int length, const char delim = ' ')
diff --git a/kit/ForKit.cpp b/kit/ForKit.cpp
index cc6759de..b678b1e5 100644
--- a/kit/ForKit.cpp
+++ b/kit/ForKit.cpp
@@ -38,6 +38,7 @@
 #include "Util.hpp"
 
 #include "common/FileUtil.hpp"
+#include "common/Seccomp.hpp"
 #include "common/SigUtil.hpp"
 #include "security.h"
 
@@ -415,6 +416,21 @@ int main(int argc, char** argv)
             std::cout << "loolforkit version details: " << version << " - " << hash << std::endl;
             DisplayVersion = true;
         }
+        else if (std::strstr(cmd, "--rlimits") == cmd)
+        {
+            eq = std::strchr(cmd, '=');
+            const std::string rlimits = std::string(eq+1);
+            std::vector<std::string> tokens = LOOLProtocol::tokenize(rlimits, ';');
+            for (const std::string& cmdLimit : tokens)
+            {
+                const auto pair = LOOLProtocol::split(cmdLimit, ':');
+                std::vector<std::string> tokensLimit = { "setconfig", pair.first, pair.second };
+                if (!Seccomp::handleSetrlimitCommand(tokensLimit))
+                {
+                    LOG_ERR("Unknown rlimits command: " << cmdLimit);
+                }
+            }
+        }
 #if ENABLE_DEBUG
         // this process has various privileges - don't run arbitrary code.
         else if (std::strstr(cmd, "--unitlib=") == cmd)
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index edf1184a..d7545dbd 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1167,6 +1167,14 @@ bool LOOLWSD::createForKit()
     args.push_back("--childroot=" + ChildRoot);
     args.push_back("--clientport=" + std::to_string(ClientPortNumber));
     args.push_back("--masterport=" + std::to_string(MasterPortNumber));
+
+    std::ostringstream ossRLimits;
+    ossRLimits << "limit_virt_mem_mb:" << getConfigValue<int>("per_document.limit_virt_mem_mb", 0);
+    ossRLimits << ";limit_data_mem_kb:" << getConfigValue<int>("per_document.limit_data_mem_kb", 0);
+    ossRLimits << ";limit_stack_mem_kb:" << getConfigValue<int>("per_document.limit_stack_mem_kb", 0);
+    ossRLimits << ";limit_file_size_mb:" << getConfigValue<int>("per_document.limit_file_size_mb", 0);
+    args.push_back("--rlimits=" + ossRLimits.str());
+
     if (UnitWSD::get().hasKitHooks())
     {
         args.push_back("--unitlib=" + UnitTestLibrary);
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index b3d0a75b..6b51ae51 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -170,7 +170,7 @@ private:
             ConfigValueGetter(config, name)(value);
             return true;
         }
-        catch (const Poco::SyntaxException&)
+        catch (const std::exception&)
         {
         }
 


More information about the Libreoffice-commits mailing list