Blame SOURCES/gvfs-1.22.5-gvfs-open-add-hack-to-close-up-dbus-daemon-race.patch

9e08f4
From 7bee91695bbe5d9228392e6da496186f02df5c39 Mon Sep 17 00:00:00 2001
9e08f4
From: Ray Strode <rstrode@redhat.com>
9e08f4
Date: Wed, 20 May 2015 16:25:01 -0400
9e08f4
Subject: [PATCH] gvfs-open: add hack to close up dbus-daemon race
9e08f4
9e08f4
If gvfs-open exits before the program it starts fully activates, then
9e08f4
the dbus-daemon may avoid doing the activating method call.
9e08f4
9e08f4
This commit works around the problem by pinging the activated application,
9e08f4
and waiting for a reply.
9e08f4
9e08f4
https://bugzilla.gnome.org/show_bug.cgi?id=746534
9e08f4
---
9e08f4
 programs/gvfs-open.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++-
9e08f4
 1 file changed, 96 insertions(+), 1 deletion(-)
9e08f4
9e08f4
diff --git a/programs/gvfs-open.c b/programs/gvfs-open.c
9e08f4
index b98d6cf..604881e 100644
9e08f4
--- a/programs/gvfs-open.c
9e08f4
+++ b/programs/gvfs-open.c
9e08f4
@@ -30,6 +30,7 @@
9e08f4
 #include <glib.h>
9e08f4
 #include <glib/gi18n.h>
9e08f4
 #include <gio/gio.h>
9e08f4
+#include <gio/gdesktopappinfo.h>
9e08f4
 
9e08f4
 static gboolean show_version = FALSE;
9e08f4
 static gchar **locations = NULL;
9e08f4
@@ -40,6 +41,68 @@ static GOptionEntry entries[] = {
9e08f4
   {NULL}
9e08f4
 };
9e08f4
 
9e08f4
+static gboolean
9e08f4
+get_bus_name_and_path_from_uri (char *uri,
9e08f4
+				char **bus_name_out,
9e08f4
+				char **object_path_out)
9e08f4
+{
9e08f4
+  GAppInfo *app_info = NULL;
9e08f4
+  char *bus_name = NULL;
9e08f4
+  char *object_path = NULL;
9e08f4
+  char *uri_scheme;
9e08f4
+  const char *filename;
9e08f4
+  char *basename = NULL;
9e08f4
+  char *p;
9e08f4
+  gboolean got_name = FALSE;
9e08f4
+
9e08f4
+  uri_scheme = g_uri_parse_scheme (uri);
9e08f4
+  if (uri_scheme && uri_scheme[0] != '\0')
9e08f4
+    app_info = g_app_info_get_default_for_uri_scheme (uri_scheme);
9e08f4
+
9e08f4
+  g_free (uri_scheme);
9e08f4
+
9e08f4
+  if (app_info == NULL)
9e08f4
+    {
9e08f4
+      GFile *file;
9e08f4
+
9e08f4
+      file = g_file_new_for_uri (uri);
9e08f4
+      app_info = g_file_query_default_handler (file, NULL, NULL);
9e08f4
+      g_object_unref (file);
9e08f4
+    }
9e08f4
+
9e08f4
+  if (app_info == NULL || !G_IS_DESKTOP_APP_INFO (app_info) ||
9e08f4
+      !g_desktop_app_info_get_boolean (G_DESKTOP_APP_INFO (app_info), "DBusActivatable"))
9e08f4
+    return FALSE;
9e08f4
+
9e08f4
+  filename = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (app_info));
9e08f4
+  if (filename == NULL)
9e08f4
+    goto out;
9e08f4
+
9e08f4
+  basename = g_path_get_basename (filename);
9e08f4
+  if (!g_str_has_suffix (basename, ".desktop"))
9e08f4
+    goto out;
9e08f4
+
9e08f4
+  basename[strlen (basename) - strlen (".desktop")] = '\0';
9e08f4
+  if (!g_dbus_is_name (basename))
9e08f4
+    goto out;
9e08f4
+
9e08f4
+  bus_name = g_strdup (basename);
9e08f4
+  object_path = g_strdup_printf ("/%s", bus_name);
9e08f4
+  for (p = object_path; *p != '\0'; p++)
9e08f4
+    if (*p == '.')
9e08f4
+      *p = '/';
9e08f4
+
9e08f4
+  *bus_name_out = g_steal_pointer (&bus_name);
9e08f4
+  *object_path_out = g_steal_pointer (&object_path);
9e08f4
+  got_name = TRUE;
9e08f4
+
9e08f4
+out:
9e08f4
+  g_clear_object (&app_info);
9e08f4
+  g_clear_pointer (&basename, g_free);
9e08f4
+
9e08f4
+  return got_name;
9e08f4
+}
9e08f4
+
9e08f4
 int
9e08f4
 main (int argc, char *argv[])
9e08f4
 {
9e08f4
@@ -104,6 +167,8 @@ main (int argc, char *argv[])
9e08f4
 
9e08f4
   do
9e08f4
     {
9e08f4
+      char *uri = NULL;
9e08f4
+
9e08f4
       res = g_app_info_launch_default_for_uri (locations[i],
9e08f4
 					       NULL,
9e08f4
 					       &error);
9e08f4
@@ -113,7 +178,8 @@ main (int argc, char *argv[])
9e08f4
 	  /* g_app_info_launch_default_for_uri() can't properly handle non-URI (local) locations */
9e08f4
 	  g_clear_error (&error);
9e08f4
 	  file = g_file_new_for_commandline_arg (locations[i]);
9e08f4
-	  res = g_app_info_launch_default_for_uri (g_file_get_uri (file),
9e08f4
+	  uri = g_file_get_uri (file);
9e08f4
+	  res = g_app_info_launch_default_for_uri (uri,
9e08f4
 						   NULL,
9e08f4
 						   &error);
9e08f4
 	  g_object_unref (file);
9e08f4
@@ -128,6 +194,35 @@ main (int argc, char *argv[])
9e08f4
 	  g_clear_error (&error);
9e08f4
 	  success = FALSE;
9e08f4
 	}
9e08f4
+
9e08f4
+      /* FIXME: This chunk of madness is a workaround for a dbus-daemon bug.
9e08f4
+       * See https://bugzilla.gnome.org/show_bug.cgi?id=746534
9e08f4
+       */
9e08f4
+      if (res)
9e08f4
+        {
9e08f4
+	  char *bus_name = NULL;
9e08f4
+	  char *object_path = NULL;
9e08f4
+
9e08f4
+	  if (get_bus_name_and_path_from_uri (uri ? uri : locations[i], &bus_name, &object_path))
9e08f4
+	    {
9e08f4
+	      GDBusConnection *connection;
9e08f4
+	      connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
9e08f4
+
9e08f4
+	      if (connection)
9e08f4
+	        g_dbus_connection_call_sync (connection,
9e08f4
+				             bus_name,
9e08f4
+				             object_path,
9e08f4
+				             "org.freedesktop.DBus.Peer",
9e08f4
+				             "Ping",
9e08f4
+				             NULL, NULL,
9e08f4
+				             G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
9e08f4
+	      g_clear_object (&connection);
9e08f4
+	      g_free (bus_name);
9e08f4
+	      g_free (object_path);
9e08f4
+	    }
9e08f4
+	}
9e08f4
+
9e08f4
+      g_free (uri);
9e08f4
     }
9e08f4
   while (locations[++i] != NULL);
9e08f4
 
9e08f4
-- 
9e08f4
2.4.3
9e08f4