vcl/headless/svpinst.cxx | 61 ++++++++++++++++++++++++++++++++----------- vcl/inc/headless/svpinst.hxx | 3 ++ 2 files changed, 49 insertions(+), 15 deletions(-)
New commits: commit 57295468a6770d7831437d83248e68bbe667d86b Author: Tor Lillqvist <t...@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.me...@collabora.com> Tested-by: Michael Meeks <michael.me...@collabora.com> diff --git a/vcl/headless/svpinst.cxx b/vcl/headless/svpinst.cxx index 7c94f66..0b24718 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> @@ -62,6 +63,15 @@ bool SvpSalInstance::isFrameAlive( const SalFrame* pFrame ) const SvpSalInstance* SvpSalInstance::s_pDefaultInstance = NULL; +static void atfork_child() +{ + if (SvpSalInstance::s_pDefaultInstance != NULL) + { + SvpSalInstance::s_pDefaultInstance->CloseWakeupPipe(); + SvpSalInstance::s_pDefaultInstance->CreateWakeupPipe(); + } +} + SvpSalInstance::SvpSalInstance( SalYieldMutex *pMutex ) : SalGenericInstance( pMutex ) { @@ -70,8 +80,43 @@ SvpSalInstance::SvpSalInstance( SalYieldMutex *pMutex ) : m_nTimeoutMS = 0; m_pTimeoutFDS[0] = m_pTimeoutFDS[1] = -1; - if (pipe (m_pTimeoutFDS) != -1) + CreateWakeupPipe(); + m_aEventGuard = osl_createMutex(); + if( s_pDefaultInstance == NULL ) + s_pDefaultInstance = this; + pthread_atfork(NULL, NULL, atfork_child); +} + +SvpSalInstance::~SvpSalInstance() +{ + if( s_pDefaultInstance == this ) + s_pDefaultInstance = NULL; + + CloseWakeupPipe(); + osl_destroyMutex( m_aEventGuard ); +} + +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; @@ -99,20 +144,6 @@ SvpSalInstance::SvpSalInstance( SalYieldMutex *pMutex ) : (void)fcntl(m_pTimeoutFDS[1], F_SETFL, flags); } } - m_aEventGuard = osl_createMutex(); - if( s_pDefaultInstance == NULL ) - s_pDefaultInstance = this; -} - -SvpSalInstance::~SvpSalInstance() -{ - if( s_pDefaultInstance == this ) - s_pDefaultInstance = NULL; - - // close 'wakeup' pipe. - close (m_pTimeoutFDS[0]); - close (m_pTimeoutFDS[1]); - osl_destroyMutex( m_aEventGuard ); } void SvpSalInstance::PostEvent( const SalFrame* pFrame, void* pData, sal_uInt16 nEvent ) diff --git a/vcl/inc/headless/svpinst.hxx b/vcl/inc/headless/svpinst.hxx index 44795d5..e004a44 100644 --- a/vcl/inc/headless/svpinst.hxx +++ b/vcl/inc/headless/svpinst.hxx @@ -97,6 +97,9 @@ public: SvpSalInstance( SalYieldMutex *pMutex ); virtual ~SvpSalInstance(); + void CloseWakeupPipe(); + void CreateWakeupPipe(); + void PostEvent( const SalFrame* pFrame, void* pData, sal_uInt16 nEvent ); bool PostedEventsInQueue(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits