[vlc-commits] Use a private dbus connection in the inhibit and telepathy modules

Mirsal Ennaime git at videolan.org
Thu Aug 11 13:26:43 CEST 2011


vlc | branch: master | Mirsal Ennaime <mirsal at mirsal.fr> | Thu Aug 11 11:38:18 2011 +0200| [b03ea8da782fda0f10279e30b08678585678adb8] | committer: Mirsal Ennaime

Use a private dbus connection in the inhibit and telepathy modules

libdbus has multiple thread-safety issues and using private connections
(ie: not shared with other vlc modules) helps avoiding some of them.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b03ea8da782fda0f10279e30b08678585678adb8
---

 modules/misc/inhibit.c     |   10 +++++++++-
 modules/notify/telepathy.c |   11 ++++++++---
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/modules/misc/inhibit.c b/modules/misc/inhibit.c
index bb976bc..14162e8 100644
--- a/modules/misc/inhibit.c
+++ b/modules/misc/inhibit.c
@@ -111,7 +111,11 @@ static int Activate( vlc_object_t *p_this )
     p_sys->p_input = NULL;
 
     dbus_error_init( &error );
-    p_sys->p_conn = dbus_bus_get( DBUS_BUS_SESSION, &error );
+
+    /* connect privately to the session bus
+     * the connection will not be shared with other vlc modules which use dbus,
+     * thus avoiding a whole class of concurrency issues */
+    p_sys->p_conn = dbus_bus_get_private( DBUS_BUS_SESSION, &error );
     if( !p_sys->p_conn )
     {
         msg_Err( p_this, "Failed to connect to the D-Bus session daemon: %s",
@@ -146,6 +150,10 @@ static void Deactivate( vlc_object_t *p_this )
         UnInhibit( p_intf, FREEDESKTOP );
     if( p_sys->i_cookie[GNOME] )
         UnInhibit( p_intf, GNOME );
+
+    /* The dbus connection is private,
+     * so we are responsible for closing it */
+    dbus_connection_close( p_sys->p_conn );
     dbus_connection_unref( p_sys->p_conn );
 
     free( p_sys );
diff --git a/modules/notify/telepathy.c b/modules/notify/telepathy.c
index d73cf06..7f6ce89 100644
--- a/modules/notify/telepathy.c
+++ b/modules/notify/telepathy.c
@@ -89,9 +89,12 @@ static int Open( vlc_object_t *p_this )
     if( !p_intf->p_sys )
         return VLC_ENOMEM;
 
-    /* connect to the session bus */
     dbus_error_init( &error );
-    p_intf->p_sys->p_conn = dbus_bus_get( DBUS_BUS_SESSION, &error );
+
+    /* connect privately to the session bus
+     * the connection will not be shared with other vlc modules which use dbus,
+     * thus avoiding a whole class of concurrency issues */
+    p_intf->p_sys->p_conn = dbus_bus_get_private( DBUS_BUS_SESSION, &error );
     if( !p_intf->p_sys->p_conn )
     {
         msg_Err( p_this, "Failed to connect to the DBus session daemon: %s",
@@ -140,7 +143,9 @@ static void Close( vlc_object_t *p_this )
     /* Do not check for VLC_ENOMEM as we're closing */
     SendToTelepathy( p_intf, "" );
 
-    /* we won't use the DBus connection anymore */
+    /* The dbus connection is private,
+     * so we are responsible for closing it */
+    dbus_connection_close( p_intf->p_sys->p_conn );
     dbus_connection_unref( p_intf->p_sys->p_conn );
 
     /* Destroy structure */



More information about the vlc-commits mailing list