[vlc-commits] dbus: start interface before hand-off (fixes #3369)

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


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jun 18 18:36:11 2017 +0300| [680ed3e386966f655aba4e3fc7bbcbdded84cdb9] | committer: Rémi Denis-Courmont

dbus: start interface before hand-off (fixes #3369)

This ensures that one instance gets the bus name before any instance
checks if the bus name is held. This fixes a race condition going all
the way back to the original VLC D-Bus interface implementation:
if multiple files are opened at the same time while no instance exists,
the new instances check the bus name for an owner before any of them
has had time to actually request and obtain the bus name. Then each
instance assumed it was the single one.

Note that there is still a race if the user closes the main instance
while trying to open files. Thits is an instrinsic user interface race,
and is unfixable.

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

 src/posix/specific.c | 48 ++++++++++++++++++++++--------------------------
 1 file changed, 22 insertions(+), 26 deletions(-)

diff --git a/src/posix/specific.c b/src/posix/specific.c
index fe26903002..8a2cb4cdab 100644
--- a/src/posix/specific.c
+++ b/src/posix/specific.c
@@ -41,15 +41,21 @@ static void system_ConfigureDbus(libvlc_int_t *vlc, int argc,
 {
 /* FIXME: could be replaced by using Unix sockets */
 #ifdef HAVE_DBUS
+# define MPRIS_APPEND "/org/mpris/MediaPlayer2/TrackList/Append"
+# define MPRIS_BUS_NAME "org.mpris.MediaPlayer2.vlc"
+# define MPRIS_OBJECT_PATH "/org/mpris/MediaPlayer2"
+# define MPRIS_TRACKLIST_INTERFACE "org.mpris.MediaPlayer2.TrackList"
+
+    dbus_threads_init_default();
+
+    if (var_InheritBool(vlc, "dbus"))
+        libvlc_InternalAddIntf(vlc, "dbus,none");
+
     if (!var_InheritBool(vlc, "one-instance")
      && !(var_InheritBool(vlc, "one-instance-when-started-from-file")
        && var_InheritBool(vlc, "started-from-file")))
          return;
 
-#define MPRIS_APPEND "/org/mpris/MediaPlayer2/TrackList/Append"
-#define MPRIS_BUS_NAME "org.mpris.MediaPlayer2.vlc"
-#define MPRIS_OBJECT_PATH "/org/mpris/MediaPlayer2"
-#define MPRIS_TRACKLIST_INTERFACE "org.mpris.MediaPlayer2.TrackList"
     for (int i = 0; i < argc; i++)
         if (argv[i][0] == ':')
         {
@@ -58,9 +64,19 @@ static void system_ConfigureDbus(libvlc_int_t *vlc, int argc,
             return;
         }
 
-    /* Initialise D-Bus interface, check for other instances */
-    dbus_threads_init_default();
+    char *name = var_GetString(vlc, "dbus-mpris-name");
+    if (name != NULL)
+    {
+        bool singleton = !strcmp(name, MPRIS_BUS_NAME);
+        free(name);
+        if (singleton)
+        {
+            msg_Dbg(vlc, "no running VLC instance - continuing normally...");
+            return; /* This is the single instance */
+        }
+    }
 
+    /* Initialise D-Bus interface, check for other instances */
     DBusError err;
     dbus_error_init(&err);
 
@@ -74,22 +90,6 @@ static void system_ConfigureDbus(libvlc_int_t *vlc, int argc,
         return;
     }
 
-    /* check if VLC is available on the bus
-     * if not: D-Bus control is not enabled on the other
-     * instance and we can't pass MRLs to it */
-    /* FIXME: This check is totally brain-dead and buggy. */
-    if (!dbus_bus_name_has_owner(conn, MPRIS_BUS_NAME, &err))
-    {
-        dbus_connection_unref(conn);
-        if (dbus_error_is_set(&err))
-        {
-            msg_Err(vlc, "D-Bus error: %s", err.message);
-            dbus_error_free(&err);
-        }
-        else
-            msg_Dbg(vlc, "no running VLC instance - continuing normally...");
-        return;
-    }
     msg_Warn(vlc, "running VLC instance - exiting...");
 
     const dbus_bool_t play = !var_InheritBool(vlc, "playlist-enqueue");
@@ -158,8 +158,4 @@ void system_Configure(libvlc_int_t *libvlc,
                       int argc, const char *const argv[])
 {
     system_ConfigureDbus(libvlc, argc, argv);
-#ifdef HAVE_DBUS
-    if (var_InheritBool(libvlc, "dbus"))
-        libvlc_InternalAddIntf(libvlc, "dbus,none");
-#endif
 }



More information about the vlc-commits mailing list