[Libreoffice-commits] core.git: vcl/headless vcl/inc

Tor Lillqvist tml at collabora.com
Fri Apr 22 15:41:37 UTC 2016


 vcl/headless/svpinst.cxx     |   57 +++++++++++++++++++++++++++++++++----------
 vcl/inc/headless/svpinst.hxx |    3 ++
 2 files changed, 47 insertions(+), 13 deletions(-)

New commits:
commit dbced8e8584b631524dacf607f752ebb734901db
Author: Tor Lillqvist <tml at collabora.com>
Date:   Wed Apr 20 13:13:16 2016 +0300

    Don't share the wakeup pipe with child processes
    
    Create a new pipe in the child process.
    
    In a normal desktop LibreOffice each fork() will be followed quickly
    by an exec(), so the FD_CLOEXEC would be enough for that. In
    LibreOfficeKit-based software that uses the preinit mechanism, though,
    the intent is that one can fork child processes without exec().
    
    This solution uses pthread_atfork(). Another way would be to add
    suitable public API callable from the LibreOfficeKit client
    initialisation code in desktop/source/lib/init.cxx to explicitly close
    and reopen the wakeup pipe in the default SvpSalInstance.
    
    Change-Id: I03fad4ce4adf14c16cb0f537b3baab58fba38922
    Reviewed-on: https://gerrit.libreoffice.org/24256
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/vcl/headless/svpinst.cxx b/vcl/headless/svpinst.cxx
index 0c71f63..65c25f1 100644
--- a/vcl/headless/svpinst.cxx
+++ b/vcl/headless/svpinst.cxx
@@ -19,6 +19,7 @@
 
 #include <unistd.h>
 #include <fcntl.h>
+#include <pthread.h>
 #include <sys/time.h>
 #include <sys/poll.h>
 
@@ -59,6 +60,15 @@ bool SvpSalInstance::isFrameAlive( const SalFrame* pFrame ) const
 
 SvpSalInstance* SvpSalInstance::s_pDefaultInstance = nullptr;
 
+static void atfork_child()
+{
+    if (SvpSalInstance::s_pDefaultInstance != nullptr)
+    {
+        SvpSalInstance::s_pDefaultInstance->CloseWakeupPipe();
+        SvpSalInstance::s_pDefaultInstance->CreateWakeupPipe();
+    }
+}
+
 SvpSalInstance::SvpSalInstance( SalYieldMutex *pMutex ) :
     SalGenericInstance( pMutex )
 {
@@ -67,8 +77,41 @@ SvpSalInstance::SvpSalInstance( SalYieldMutex *pMutex ) :
     m_nTimeoutMS            = 0;
 
     m_pTimeoutFDS[0] = m_pTimeoutFDS[1] = -1;
-    if (pipe (m_pTimeoutFDS) != -1)
+    CreateWakeupPipe();
+    if( s_pDefaultInstance == nullptr )
+        s_pDefaultInstance = this;
+    pthread_atfork(NULL, NULL, atfork_child);
+}
+
+SvpSalInstance::~SvpSalInstance()
+{
+    if( s_pDefaultInstance == this )
+        s_pDefaultInstance = NULL;
+
+    CloseWakeupPipe();
+}
+
+void SvpSalInstance::CloseWakeupPipe()
+{
+    if (m_pTimeoutFDS[0] != -1)
     {
+        SAL_INFO("vcl.headless", "CloseWakeupPipe: Closing inherited wakeup pipe: [" << m_pTimeoutFDS[0] << "," << m_pTimeoutFDS[1] << "]");
+        close (m_pTimeoutFDS[0]);
+        close (m_pTimeoutFDS[1]);
+        m_pTimeoutFDS[0] = m_pTimeoutFDS[1] = -1;
+    }
+}
+
+void SvpSalInstance::CreateWakeupPipe()
+{
+    if (pipe (m_pTimeoutFDS) == -1)
+    {
+        SAL_WARN("vcl.headless", "Could not create wakeup pipe: " << strerror(errno));
+    }
+    else
+    {
+        SAL_INFO("vcl.headless", "CreateWakeupPipe: Created wakeup pipe: [" << m_pTimeoutFDS[0] << "," << m_pTimeoutFDS[1] << "]");
+
         // initialize 'wakeup' pipe.
         int flags;
 
@@ -96,18 +139,6 @@ SvpSalInstance::SvpSalInstance( SalYieldMutex *pMutex ) :
             (void)fcntl(m_pTimeoutFDS[1], F_SETFL, flags);
         }
     }
-    if( s_pDefaultInstance == nullptr )
-        s_pDefaultInstance = this;
-}
-
-SvpSalInstance::~SvpSalInstance()
-{
-    if( s_pDefaultInstance == this )
-        s_pDefaultInstance = nullptr;
-
-    // close 'wakeup' pipe.
-    close (m_pTimeoutFDS[0]);
-    close (m_pTimeoutFDS[1]);
 }
 
 void SvpSalInstance::PostEvent(const SalFrame* pFrame, ImplSVEvent* pData, sal_uInt16 nEvent)
diff --git a/vcl/inc/headless/svpinst.hxx b/vcl/inc/headless/svpinst.hxx
index 1505a3b..76250b1 100644
--- a/vcl/inc/headless/svpinst.hxx
+++ b/vcl/inc/headless/svpinst.hxx
@@ -92,6 +92,9 @@ public:
     SvpSalInstance( SalYieldMutex *pMutex );
     virtual ~SvpSalInstance();
 
+    void                    CloseWakeupPipe();
+    void                    CreateWakeupPipe();
+
     void                    PostEvent(const SalFrame* pFrame, ImplSVEvent* pData, sal_uInt16 nEvent);
 
 #ifdef ANDROID


More information about the Libreoffice-commits mailing list