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

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


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jun 18 18:34:56 2017 +0300| [5249120d72703fe0c34037b69df888c16a1329dc] | 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=5249120d72703fe0c34037b69df888c16a1329dc
---

 modules/control/dbus/dbus.c | 23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/modules/control/dbus/dbus.c b/modules/control/dbus/dbus.c
index 3f41059d27..8c5aea7904 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,23 +208,17 @@ 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 );
+            msg_Err( p_intf, "listening on dbus as: %s", unique_service );
             var_SetString(p_intf->obj.libvlc, "dbus-mpris-name",
                           unique_service);
         }
     }
     else
     {
-        msg_Dbg( p_intf, "listening on dbus as: %s", DBUS_MPRIS_BUS_NAME );
+        msg_Err( p_intf, "listening on dbus as: %s", DBUS_MPRIS_BUS_NAME );
         var_SetString(p_intf->obj.libvlc, "dbus-mpris-name",
                       DBUS_MPRIS_BUS_NAME);
     }



More information about the vlc-commits mailing list