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

Michael Meeks michael.meeks at collabora.com
Mon Apr 16 20:58:00 UTC 2018


 common/Util.cpp |   15 +++++++++++++++
 common/Util.hpp |    3 +++
 kit/ForKit.cpp  |    3 +++
 3 files changed, 21 insertions(+)

New commits:
commit 03bbe526650d25bcd0864e0dad087bb1e1396323
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Mon Apr 16 20:03:01 2018 +0100

    Ensure the forkit does not have lingering threads after preinit.
    
    Change-Id: I216a03a0ada628189355ebfd4016bf6033430eef

diff --git a/common/Util.cpp b/common/Util.cpp
index 962b5b4c1..a03cf4c46 100644
--- a/common/Util.cpp
+++ b/common/Util.cpp
@@ -140,6 +140,21 @@ namespace Util
         return newTmp;
     }
 
+    int getProcessThreadCount()
+    {
+        DIR *fdDir = opendir("/proc/self/task");
+        if (!fdDir)
+        {
+            LOG_ERR("No proc mounted");
+            return -1;
+        }
+        int tasks = 0;
+        while (readdir(fdDir))
+            tasks++;
+        closedir(fdDir);
+        return tasks;
+    }
+
     // close what we have - far faster than going up to a 1m open_max eg.
     static bool closeFdsFromProc()
     {
diff --git a/common/Util.hpp b/common/Util.hpp
index db5217fbe..cd59f7d95 100644
--- a/common/Util.hpp
+++ b/common/Util.hpp
@@ -48,6 +48,9 @@ namespace Util
     /// Create randomized temporary directory
     std::string createRandomTmpDir();
 
+    /// Get number of threads in this process or -1 on error
+    int getProcessThreadCount();
+
     /// Spawn a process if stdInput is non-NULL it contains a writable descriptor
     /// to send data to the child.
     int spawnProcess(const std::string &cmd, const std::vector<std::string> &args,
diff --git a/kit/ForKit.cpp b/kit/ForKit.cpp
index 3dac8ac18..89f49e53d 100644
--- a/kit/ForKit.cpp
+++ b/kit/ForKit.cpp
@@ -527,6 +527,9 @@ int main(int argc, char** argv)
     if (!globalPreinit(loTemplate))
         std::_Exit(Application::EXIT_SOFTWARE);
 
+    if (Util::getProcessThreadCount() != 1)
+        LOG_ERR("Error: forkit has more than a single thread after pre-init");
+
     LOG_INF("Preinit stage OK.");
 
     // We must have at least one child, more are created dynamically.


More information about the Libreoffice-commits mailing list