[vlc-commits] dbus: fix naming of multiple instances

Rémi Denis-Courmont git at videolan.org
Sun Jun 18 17:58:38 CEST 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jun 18 18:34:56 2017 +0300| [05b779fb31f83f155b0e4cf65cf2d78e0e1bcb6e] | committer: Rémi Denis-Courmont

dbus: fix naming of multiple instances

The do-not-queue flag is necessary to ensure that the bus name is
obtained immediately or not at all. Without it, each VLC instances gets
put into the queue for the same name.

Also, failure must be checked from the return value of the function,
not (typically) the low-level error flag.

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

 modules/control/dbus/dbus.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/modules/control/dbus/dbus.c b/modules/control/dbus/dbus.c
index 3f41059d27..87be4d2472 100644
--- a/modules/control/dbus/dbus.c
+++ b/modules/control/dbus/dbus.c
@@ -193,14 +193,11 @@ static int Open( vlc_object_t *p_this )
             &dbus_mpris_vtable, p_this );
 
     /* Try to register org.mpris.MediaPlayer2.vlc */
+    const unsigned bus_flags = DBUS_NAME_FLAG_DO_NOT_QUEUE;
     var_Create(p_intf->obj.libvlc, "dbus-mpris-name", VLC_VAR_STRING);
-    dbus_bus_request_name( p_conn, DBUS_MPRIS_BUS_NAME, 0, &error );
-    if( dbus_error_is_set( &error ) )
+    if( dbus_bus_request_name( p_conn, DBUS_MPRIS_BUS_NAME, bus_flags, NULL )
+                                     != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER )
     {
-        msg_Dbg( p_this, "Failed to get service name %s: %s",
-                 DBUS_MPRIS_BUS_NAME, error.message );
-        dbus_error_free( &error );
-
         /* Register an instance-specific well known name of the form
          * org.mpris.MediaPlayer2.vlc.instanceXXXX where XXXX is the
          * current Process ID */
@@ -211,14 +208,8 @@ static int Open( vlc_object_t *p_this )
                   DBUS_MPRIS_BUS_NAME"."DBUS_INSTANCE_ID_PREFIX"%"PRIu32,
                   (uint32_t)getpid() );
 
-        dbus_bus_request_name( p_conn, unique_service, 0, &error );
-        if( dbus_error_is_set( &error ) )
-        {
-            msg_Err( p_this, "Failed to get service name %s: %s",
-                     DBUS_MPRIS_BUS_NAME, error.message );
-            dbus_error_free( &error );
-        }
-        else
+        if( dbus_bus_request_name( p_conn, unique_service, bus_flags, NULL )
+                                     == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER )
         {
             msg_Dbg( p_intf, "listening on dbus as: %s", unique_service );
             var_SetString(p_intf->obj.libvlc, "dbus-mpris-name",



More information about the vlc-commits mailing list