[PATCH] Change in core[libreoffice-3-6]: Related fdo#33484: Terminate OfficeIPCThread by closing the ...

Stephan Bergmann (via Code Review) gerrit at gerrit.libreoffice.org
Thu Jan 17 03:03:44 PST 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/1734

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/34/1734/1

Related fdo#33484: Terminate OfficeIPCThread by closing the accepting pipe

... (and setting mbDowning to indicate an error returned from accept() is due to
termination) instead of setting up an extra pipe connection to send an
"InternalIPC::TerminateThread" message (which allegedly caused deadlocks, see
<https://gerrit.libreoffice.org/#/c/1311/> "Change Idf933915: office ipc: use
timeout pipe feature when connecting to self").

(cherry picked from commit 4ce2602befd59e69264d8e4ced8730b40c2b947c)
Conflicts:
	desktop/source/app/officeipcthread.cxx
	desktop/source/app/officeipcthread.hxx

(cherry picked from commit 6527b8a135c20e223a6fcf7c49835205a99ff02a)

Change-Id: Id302ca13112fc409685e7665b38f1030704a0ccf
---
M desktop/source/app/officeipcthread.cxx
M desktop/source/app/officeipcthread.hxx
2 files changed, 23 insertions(+), 32 deletions(-)



diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx
index 452a3b5..1d37ee0 100644
--- a/desktop/source/app/officeipcthread.cxx
+++ b/desktop/source/app/officeipcthread.cxx
@@ -60,8 +60,6 @@
 using ::rtl::OUString;
 using ::rtl::OUStringBuffer;
 
-const char  *OfficeIPCThread::sc_aTerminationSequence = "InternalIPC::TerminateThread";
-const int OfficeIPCThread::sc_nTSeqLength = 28;
 const char  *OfficeIPCThread::sc_aShowSequence = "-tofront";
 const int OfficeIPCThread::sc_nShSeqLength = 5;
 const char  *OfficeIPCThread::sc_aConfirmationSequence = "InternalIPC::ProcessingDone";
@@ -436,8 +434,6 @@
 
     rtl::Reference< OfficeIPCThread > pThread(new OfficeIPCThread);
 
-    pThread->maPipeIdent = OUString( "SingleOfficeIPC_"  );
-
     // The name of the named pipe is created with the hashcode of the user installation directory (without /user). We have to retrieve
     // this information from a unotools implementation.
     ::utl::Bootstrap::PathStatus aLocateResult = ::utl::Bootstrap::locateUserInstallation( aUserInstallPath );
@@ -494,19 +490,19 @@
     if ( aUserInstallPathHashCode.isEmpty() )
         return IPC_STATUS_BOOTSTRAP_ERROR; // Something completely broken, we cannot create a valid hash code!
 
-    pThread->maPipeIdent = pThread->maPipeIdent + aUserInstallPathHashCode;
+    OUString aPipeIdent( "SingleOfficeIPC_" + aUserInstallPathHashCode );
 
     PipeMode nPipeMode = PIPEMODE_DONTKNOW;
     do
     {
         osl::Security &rSecurity = Security::get();
         // Try to create pipe
-        if ( pThread->maPipe.create( pThread->maPipeIdent.getStr(), osl_Pipe_CREATE, rSecurity ))
+        if ( pThread->maPipe.create( aPipeIdent.getStr(), osl_Pipe_CREATE, rSecurity ))
         {
             // Pipe created
             nPipeMode = PIPEMODE_CREATED;
         }
-        else if( pThread->maPipe.create( pThread->maPipeIdent.getStr(), osl_Pipe_OPEN, rSecurity )) // Creation not successfull, now we try to connect
+        else if( pThread->maPipe.create( aPipeIdent.getStr(), osl_Pipe_OPEN, rSecurity )) // Creation not successfull, now we try to connect
         {
             osl::StreamPipe aStreamPipe(pThread->maPipe.getHandle());
             char pReceiveBuffer[sc_nCSASeqLength + 1];
@@ -610,18 +606,8 @@
             pGlobalOfficeIPCThread);
         pGlobalOfficeIPCThread.clear();
 
-        // send thread a termination message
-        // this is done so the subsequent join will not hang
-        // because the thread hangs in accept of pipe
-        osl::StreamPipe aPipe ( pOfficeIPCThread->maPipeIdent, osl_Pipe_OPEN, Security::get() );
-        if (aPipe.is())
-        {
-            aPipe.send( sc_aTerminationSequence, sc_nTSeqLength+1 ); // also send 0-byte
-
-            // close the pipe so that the streampipe on the other
-            // side produces EOF
-            aPipe.close();
-        }
+        pOfficeIPCThread->mbDowning = true;
+        pOfficeIPCThread->maPipe.close();
 
         // release mutex to avoid deadlocks
         aMutex.clear();
@@ -686,22 +672,23 @@
             // down during wait
             osl::ClearableMutexGuard aGuard( GetMutex() );
 
-            if (!mbDowning)
+            if ( mbDowning )
             {
-                // notify client we're ready to process its args
-                int nBytes = 0;
-                int nResult = 0;
-                while (
-                    (nResult = maStreamPipe.send(sc_aSendArgumentsSequence+nBytes, sc_nCSASeqLength-nBytes))>0 &&
-                    ((nBytes += nResult) < sc_nCSASeqLength) ) ;
+                break;
             }
+
+            // notify client we're ready to process its args
+            int nBytes = 0;
+            int nResult;
+            while (
+                (nResult = maStreamPipe.send(sc_aSendArgumentsSequence+nBytes, sc_nCSASeqLength-nBytes))>0 &&
+                ((nBytes += nResult) < sc_nCSASeqLength) ) ;
             maStreamPipe.write("\0", 1);
 
             // test byte by byte
             const int nBufSz = 2048;
             char pBuf[nBufSz];
-            int nBytes = 0;
-            int nResult = 0;
+            nBytes = 0;
             rtl::OStringBuffer aBuf;
             // read into pBuf until '\0' is read or read-error
             while ((nResult=maStreamPipe.recv( pBuf+nBytes, nBufSz-nBytes))>0) {
@@ -719,9 +706,6 @@
             if (aArguments.isEmpty())
                 continue;
 
-            // is this a termination message ? if so, terminate
-            if (aArguments.equalsL(sc_aTerminationSequence, sc_nTSeqLength) || mbDowning)
-                return;
             std::auto_ptr< CommandLineArgs > aCmdLineArgs;
             try
             {
@@ -938,6 +922,14 @@
         }
         else
         {
+            {
+                osl::MutexGuard aGuard( GetMutex() );
+                if ( mbDowning )
+                {
+                    break;
+                }
+            }
+
 #if (OSL_DEBUG_LEVEL > 1) || defined DBG_UTIL
             fprintf( stderr, "Error on accept: %d\n", (int)nError );
 #endif
diff --git a/desktop/source/app/officeipcthread.hxx b/desktop/source/app/officeipcthread.hxx
index ba40b57..09e56da 100644
--- a/desktop/source/app/officeipcthread.hxx
+++ b/desktop/source/app/officeipcthread.hxx
@@ -82,7 +82,6 @@
 
     osl::Pipe                   maPipe;
     osl::StreamPipe             maStreamPipe;
-    rtl::OUString               maPipeIdent;
     bool                        mbDowning;
     bool                        mbRequestsEnabled;
     int                         mnPendingRequests;

-- 
To view, visit https://gerrit.libreoffice.org/1734
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id302ca13112fc409685e7665b38f1030704a0ccf
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-3-6
Gerrit-Owner: Stephan Bergmann <sbergman at redhat.com>



More information about the LibreOffice mailing list