kbrown / rpms / libreoffice

Forked from rpms/libreoffice 2 years ago
Clone

Blame SOURCES/0005-Resolves-rhbz-144437-make-gnome-documents-not-crash-.patch

91334d
From 226b7436988f7a0e4c7d06353c630f10047ac7f6 Mon Sep 17 00:00:00 2001
91334d
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
91334d
Date: Mon, 8 May 2017 15:26:22 +0100
91334d
Subject: [PATCH] Resolves: rhbz#144437 make gnome-documents not crash the
91334d
 whole time
91334d
91334d
accept that once initted that LibreOffice cannot be deinitted and reinited
91334d
(without lots of work), but allow the main loop to quit and restart so LOKs
91334d
thread can run and exit successfully, new LOK connections will restart the main
91334d
loop.
91334d
91334d
The buckets of global state continues to be valid the whole time this way
91334d
91334d
Change-Id: Ide54c0df2ce4065f7c192ae8c2cedfaaa2b58d72
91334d
---
91334d
 desktop/source/app/app.cxx               |  2 +-
91334d
 desktop/source/app/officeipcthread.cxx   |  9 +++++++--
91334d
 desktop/source/app/officeipcthread.hxx   |  2 +-
91334d
 desktop/source/lib/init.cxx              |  5 ++++-
91334d
 framework/source/services/desktop.cxx    |  8 +++++---
91334d
 libreofficekit/source/gtk/lokdocview.cxx | 27 ++++++++++++++++++---------
91334d
 vcl/source/app/svmain.cxx                |  8 ++++++++
91334d
 7 files changed, 44 insertions(+), 17 deletions(-)
91334d
91334d
diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
91334d
index df79f41..dc7ff1e 100644
91334d
--- a/desktop/source/app/app.cxx
91334d
+++ b/desktop/source/app/app.cxx
91334d
@@ -1998,7 +1998,7 @@ IMPL_LINK_NOARG(Desktop, OpenClients_Impl, void*, void)
91334d
         // When this server closes down it attempts to recreate the pipe (in RequestHandler::Disable()).
91334d
         // It's possible that the client has a pending connection request.
91334d
         // When the IPC thread is not running, this connection locks (because maPipe.accept()) is never called
91334d
-        RequestHandler::SetReady();
91334d
+        RequestHandler::SetReady(true);
91334d
         OpenClients();
91334d
 
91334d
         CloseSplashScreen();
91334d
diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx
91334d
index 7a2fd46..5ea5f41 100644
91334d
--- a/desktop/source/app/officeipcthread.cxx
91334d
+++ b/desktop/source/app/officeipcthread.cxx
91334d
@@ -939,6 +939,8 @@ void RequestHandler::Disable()
91334d
             handler->mIpcThread->join();
91334d
             handler->mIpcThread.clear();
91334d
         }
91334d
+
91334d
+        handler->cReady.reset();
91334d
     }
91334d
 }
91334d
 
91334d
@@ -953,12 +955,15 @@ RequestHandler::~RequestHandler()
91334d
     assert(!mIpcThread.is());
91334d
 }
91334d
 
91334d
-void RequestHandler::SetReady()
91334d
+void RequestHandler::SetReady(bool bIsReady)
91334d
 {
91334d
     osl::MutexGuard g(GetMutex());
91334d
     if (pGlobal.is())
91334d
     {
91334d
-        pGlobal->cReady.set();
91334d
+        if (bIsReady)
91334d
+            pGlobal->cReady.set();
91334d
+        else
91334d
+            pGlobal->cReady.reset();
91334d
     }
91334d
 }
91334d
 
91334d
diff --git a/desktop/source/app/officeipcthread.hxx b/desktop/source/app/officeipcthread.hxx
91334d
index 2826aba..2b58ce4 100644
91334d
--- a/desktop/source/app/officeipcthread.hxx
91334d
+++ b/desktop/source/app/officeipcthread.hxx
91334d
@@ -122,7 +122,7 @@ class RequestHandler: public salhelper::SimpleReferenceObject
91334d
     static Status               Enable(bool ipc);
91334d
     static void                 Disable();
91334d
     // start dispatching events...
91334d
-    static void                 SetReady();
91334d
+    static void                 SetReady(bool bIsReady);
91334d
     static void                 WaitForReady();
91334d
 
91334d
     bool                        AreRequestsEnabled() const { return mState == State::RequestsEnabled; }
91334d
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
91334d
index 9df6471..14c7bfd 100644
91334d
--- a/desktop/source/lib/init.cxx
91334d
+++ b/desktop/source/lib/init.cxx
91334d
@@ -2742,10 +2742,12 @@ static void lo_startmain(void*)
91334d
 {
91334d
     osl_setThreadName("lo_startmain");
91334d
 
91334d
-    if (GetpApp())
91334d
+    if (comphelper::SolarMutex::get())
91334d
         Application::GetSolarMutex().tryToAcquire();
91334d
 
91334d
     soffice_main();
91334d
+
91334d
+    Application::ReleaseSolarMutex();
91334d
 }
91334d
 
91334d
 static bool bInitialized = false;
91334d
@@ -2912,6 +2914,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
91334d
             SAL_INFO("lok", "Enabling RequestHandler");
91334d
             RequestHandler::Enable(false);
91334d
             SAL_INFO("lok", "Starting soffice_main");
91334d
+            RequestHandler::SetReady(false);
91334d
             pLib->maThread = osl_createThread(lo_startmain, nullptr);
91334d
             SAL_INFO("lok", "Waiting for RequestHandler");
91334d
             RequestHandler::WaitForReady();
91334d
diff --git a/framework/source/services/desktop.cxx b/framework/source/services/desktop.cxx
91334d
index 20afab1..6f6412a 100644
91334d
--- a/framework/source/services/desktop.cxx
91334d
+++ b/framework/source/services/desktop.cxx
91334d
@@ -59,6 +59,7 @@
91334d
 #include <com/sun/star/frame/XTerminateListener2.hpp>
91334d
 
91334d
 #include <comphelper/sequence.hxx>
91334d
+#include <comphelper/lok.hxx>
91334d
 #include <cppuhelper/supportsservice.hxx>
91334d
 #include <rtl/instance.hxx>
91334d
 #include <vcl/svapp.hxx>
91334d
@@ -228,8 +229,9 @@ sal_Bool SAL_CALL Desktop::terminate()
91334d
 
91334d
     // try to close all open frames.
91334d
     // Allow using of any UI ... because Desktop.terminate() was designed as UI functionality in the past.
91334d
-    bool bIsEventTestingMode = Application::IsEventTestingModeEnabled();
91334d
-    bool bFramesClosed = impl_closeFrames(!bIsEventTestingMode);
91334d
+    bool bRestartableMainLoop = Application::IsEventTestingModeEnabled() ||
91334d
+                                comphelper::LibreOfficeKit::isActive();
91334d
+    bool bFramesClosed = impl_closeFrames(!bRestartableMainLoop);
91334d
 
91334d
     // Ask normal terminate listener. They could stop terminating the process.
91334d
     Desktop::TTerminateListenerList lCalledTerminationListener;
91334d
@@ -241,7 +243,7 @@ sal_Bool SAL_CALL Desktop::terminate()
91334d
         return false;
91334d
     }
91334d
 
91334d
-    if (bIsEventTestingMode)
91334d
+    if (bRestartableMainLoop)
91334d
     {
91334d
         Application::Quit();
91334d
         return true;
91334d
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
91334d
index 6d05b7a..5d64d7b 100644
91334d
--- a/libreofficekit/source/gtk/lokdocview.cxx
91334d
+++ b/libreofficekit/source/gtk/lokdocview.cxx
91334d
@@ -2610,16 +2610,25 @@ static void lok_doc_view_destroy (GtkWidget* widget)
91334d
 
91334d
     aGuard.unlock();
91334d
 
91334d
-    if (priv->m_pDocument && priv->m_pDocument->pClass->getViewsCount(priv->m_pDocument) > 1)
91334d
-    {
91334d
-        priv->m_pDocument->pClass->destroyView(priv->m_pDocument, priv->m_nViewId);
91334d
-    }
91334d
-    else
91334d
+    if (priv->m_pDocument)
91334d
     {
91334d
-        if (priv->m_pDocument)
91334d
-            priv->m_pDocument->pClass->destroy (priv->m_pDocument);
91334d
-        if (priv->m_pOffice)
91334d
-            priv->m_pOffice->pClass->destroy (priv->m_pOffice);
91334d
+        if (priv->m_pDocument->pClass->getViewsCount(priv->m_pDocument) > 1)
91334d
+        {
91334d
+            priv->m_pDocument->pClass->destroyView(priv->m_pDocument, priv->m_nViewId);
91334d
+        }
91334d
+        else
91334d
+        {
91334d
+            if (priv->m_pDocument)
91334d
+            {
91334d
+                priv->m_pDocument->pClass->destroy (priv->m_pDocument);
91334d
+                priv->m_pDocument = nullptr;
91334d
+            }
91334d
+            if (priv->m_pOffice)
91334d
+            {
91334d
+                priv->m_pOffice->pClass->destroy (priv->m_pOffice);
91334d
+                priv->m_pOffice = nullptr;
91334d
+            }
91334d
+        }
91334d
     }
91334d
 
91334d
     GTK_WIDGET_CLASS (lok_doc_view_parent_class)->destroy (widget);
91334d
diff --git a/vcl/source/app/svmain.cxx b/vcl/source/app/svmain.cxx
91334d
index 2cd6137..a5f7807 100644
91334d
--- a/vcl/source/app/svmain.cxx
91334d
+++ b/vcl/source/app/svmain.cxx
91334d
@@ -84,6 +84,7 @@
91334d
 #include <com/sun/star/lang/XComponent.hpp>
91334d
 #include <com/sun/star/frame/Desktop.hpp>
91334d
 
91334d
+#include <comphelper/lok.hxx>
91334d
 #include <cppuhelper/implbase.hxx>
91334d
 #include <uno/current_context.hxx>
91334d
 
91334d
@@ -361,6 +362,13 @@ VCLUnoWrapperDeleter::disposing(lang::EventObject const& /* rSource */)
91334d
 
91334d
 void DeInitVCL()
91334d
 {
91334d
+    //rhbz#1444437, when using LibreOffice like a library you can't realistically
91334d
+    //tear everything down and recreate them on the next call, there's too many
91334d
+    //(c++) singletons that point to stuff that gets deleted during shutdown
91334d
+    //which won't be recreated on restart.
91334d
+    if (comphelper::LibreOfficeKit::isActive())
91334d
+        return;
91334d
+
91334d
     {
91334d
         SolarMutexReleaser r; // unblock threads blocked on that so we can join
91334d
         ::comphelper::JoinAsyncEventNotifiers();
91334d
-- 
91334d
2.13.0
91334d