[Libreoffice-commits] core.git: 2 commits - sd/source

Stephan Bergmann sbergman at redhat.com
Mon Oct 14 09:01:43 PDT 2013


 sd/source/ui/dlg/RemoteDialog.cxx                  |    2 +-
 sd/source/ui/dlg/RemoteDialogClientBox.cxx         |    7 +++----
 sd/source/ui/dlg/RemoteDialogClientBox.hxx         |    8 ++------
 sd/source/ui/remotecontrol/AvahiNetworkService.cxx |   10 ++++++++++
 sd/source/ui/remotecontrol/BluetoothServer.cxx     |    8 ++++++++
 5 files changed, 24 insertions(+), 11 deletions(-)

New commits:
commit 0f1357200ee710e84389e927859eac75d24323d3
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Mon Oct 14 17:46:57 2013 +0200

    D-Bus is not thread safe
    
    ...so it could happen that both the main thread at
    
    > internal_bus_get
    > dbus_bus_get_private
    > avahi_dbus_bus_get
    > avahi_client_new
    > sd::AvahiNetworkService::setup
    > sd::DiscoveryService::DiscoveryService
    > sd::DiscoveryService::setup
    > SdDLL::RegisterRemotes
    [...]
    
    as well as the thread
    
    > internal_bus_get
    > dbus_bus_get
    > dbusConnectToNameOnBus
    > sd::BluetoothServer::run
    > threadFunc
    > osl_thread_start_Impl
    > start_thread
    
    spawned from the main thread at
    
    > sd::BluetoothServer::setup
    > sd::RemoteServer::setup
    > SdDLL::RegisterRemotes
    [...]
    
    are in D-Bus's internal_bus_get simultaneously (with disastrous consequences,
    like SEGV) despite the _DBUS_LOCK(bus) there, unless you previously called
    dbus_threads_init_default.  (Which the D-Bus documentation makes you believe can
    be called from multiple threads, though a look at the implemenation makes it
    clear that it really should be called from the main thread before any other
    threads are created---which we still don't do; oh my.)
    
    Other places that (indirectly) use D-Bus (tubes/source/file-transfer-helper.c,
    vcl/generic/fontmanager/fontconfig.cxx, vcl/unx/gtk/window/gtksalframe.cxx might
    need this, too.
    
    Change-Id: I912829c615b46b05a89c07bd044b04f1e5f5e7ba

diff --git a/sd/source/ui/remotecontrol/AvahiNetworkService.cxx b/sd/source/ui/remotecontrol/AvahiNetworkService.cxx
index 8fc4eb7..34b94a3 100644
--- a/sd/source/ui/remotecontrol/AvahiNetworkService.cxx
+++ b/sd/source/ui/remotecontrol/AvahiNetworkService.cxx
@@ -8,6 +8,7 @@
  */
 #include <time.h>
 #include <iostream>
+#include <new>
 #include <stdlib.h>
 #include <assert.h>
 
@@ -20,6 +21,8 @@
 #include <avahi-common/timeval.h>
 #include <avahi-common/thread-watch.h>
 
+#include <dbus/dbus.h>
+
 #include <sal/log.hxx>
 
 #include "AvahiNetworkService.hxx"
@@ -149,6 +152,13 @@ static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UN
 }
 
 void AvahiNetworkService::setup() {
+    // Avahi internally uses D-Bus, which requires the following in order to be
+    // thread-safe (and we potentially access D-Bus from different threads in
+    // different places of the code base):
+    if (!dbus_threads_init_default()) {
+        throw std::bad_alloc();
+    }
+
    int error = 0;
    avahiService = this;
    if (!(threaded_poll = avahi_threaded_poll_new())) {
diff --git a/sd/source/ui/remotecontrol/BluetoothServer.cxx b/sd/source/ui/remotecontrol/BluetoothServer.cxx
index ccdf03f..1deab3c 100644
--- a/sd/source/ui/remotecontrol/BluetoothServer.cxx
+++ b/sd/source/ui/remotecontrol/BluetoothServer.cxx
@@ -11,6 +11,7 @@
 
 #include <iostream>
 #include <iomanip>
+#include <new>
 
 #include <sal/log.hxx>
 
@@ -586,6 +587,13 @@ BluetoothServer::BluetoothServer( std::vector<Communicator*>* pCommunicators )
     mpCommunicators( pCommunicators )
 {
 #ifdef LINUX_BLUETOOTH
+    // D-Bus requires the following in order to be thread-safe (and we
+    // potentially access D-Bus from different threads in different places of
+    // the code base):
+    if (!dbus_threads_init_default()) {
+        throw std::bad_alloc();
+    }
+
     mpImpl.reset(new BluetoothServer::Impl());
 #endif
 }
commit e202ea3ab830f64b1305b6a6031a807a2c12ebdc
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Mon Oct 14 15:23:05 2013 +0200

    Remove unused/null sd::ClientBox::m_pServer
    
    Change-Id: I5d79bcd75088d5ba2aa773ebf0809281cab07924

diff --git a/sd/source/ui/dlg/RemoteDialog.cxx b/sd/source/ui/dlg/RemoteDialog.cxx
index 8aec838..5da2882 100644
--- a/sd/source/ui/dlg/RemoteDialog.cxx
+++ b/sd/source/ui/dlg/RemoteDialog.cxx
@@ -22,7 +22,7 @@ RemoteDialog::RemoteDialog( Window *pWindow ) :
     ModalDialog( pWindow, SdResId( DLG_PAIR_REMOTE ) ),
     mButtonConnect(     this, SdResId( BTN_CONNECT ) ),
     mButtonCancel(      this, SdResId( BTN_CANCEL ) ),
-    mClientBox(         this, NULL, SdResId( LB_SERVERS ) )
+    mClientBox(         this, SdResId( LB_SERVERS ) )
 {
     FreeResource();
 
diff --git a/sd/source/ui/dlg/RemoteDialogClientBox.cxx b/sd/source/ui/dlg/RemoteDialogClientBox.cxx
index bce4935..f1eef9d 100644
--- a/sd/source/ui/dlg/RemoteDialogClientBox.cxx
+++ b/sd/source/ui/dlg/RemoteDialogClientBox.cxx
@@ -21,6 +21,7 @@
 
 #include "RemoteDialogClientBox.hxx"
 #include "RemoteDialog.hrc"
+#include "RemoteServer.hxx"
 
 #include "comphelper/processfactory.hxx"
 #include "com/sun/star/i18n/CollatorOptions.hpp"
@@ -62,8 +63,7 @@ ClientRemovedListener::~ClientRemovedListener()
 //------------------------------------------------------------------------------
 // ClientBox
 //------------------------------------------------------------------------------
-ClientBox::ClientBox( Dialog* pParent, RemoteServer *pServer,
-                      const SdResId& aId ) :
+ClientBox::ClientBox( Dialog* pParent, const SdResId& aId ) :
     Control( pParent, aId ),
     m_bHasScrollBar( false ),
     m_bHasActive( false ),
@@ -77,8 +77,7 @@ ClientBox::ClientBox( Dialog* pParent, RemoteServer *pServer,
     m_nExtraHeight( 2 ),
     m_aPinBox( this, SdResId( INPUT_PIN ) ),
     m_aPinDescription( this, SdResId( TEXT_PIN ) ),
-    m_pScrollBar( new ScrollBar( this, WB_VERT ) ),
-    m_pServer( pServer )
+    m_pScrollBar( new ScrollBar( this, WB_VERT ) )
 {
     m_pScrollBar->SetScrollHdl( LINK( this, ClientBox, ScrollHdl ) );
     m_pScrollBar->EnableDrag();
diff --git a/sd/source/ui/dlg/RemoteDialogClientBox.hxx b/sd/source/ui/dlg/RemoteDialogClientBox.hxx
index 9c59057..522225a 100644
--- a/sd/source/ui/dlg/RemoteDialogClientBox.hxx
+++ b/sd/source/ui/dlg/RemoteDialogClientBox.hxx
@@ -32,7 +32,6 @@
 
 #include <boost/shared_ptr.hpp>
 
-#include "RemoteServer.hxx"
 #include "sdresid.hxx"
 
 namespace sd {
@@ -48,6 +47,7 @@ namespace sd {
 //                          struct ClientBoxEntry
 //------------------------------------------------------------------------------
 struct ClientBoxEntry;
+struct ClientInfo;
 
 typedef ::boost::shared_ptr< ClientBoxEntry > TClientBoxEntry;
 
@@ -112,7 +112,6 @@ class ClientBox:
 
     com::sun::star::uno::Reference< ClientRemovedListener > m_xRemoveListener;
 
-    RemoteServer      *m_pServer;
     //This mutex is used for synchronizing access to m_vEntries.
     //Currently it is used to synchronize adding, removing entries and
     //functions like getItemName, getItemDescription, etc. to prevent
@@ -141,8 +140,7 @@ class ClientBox:
 
 
 public:
-                    ClientBox( Dialog* pParent, RemoteServer *pServer,
-                               const SdResId& aId );
+                    ClientBox( Dialog* pParent, const SdResId& aId );
                    ~ClientBox();
 
     void    MouseButtonDown( const MouseEvent& rMEvt );
@@ -174,8 +172,6 @@ public:
     void            checkEntries();
 
     OUString getPin();
-
-    RemoteServer*    getServer() const { return m_pServer; }
 };
 
 }


More information about the Libreoffice-commits mailing list