[gnome-settings-daemon/gnome-3-4] media-keys: Get the environment from gnome-keyring



commit 9d7ea1d0b8b90b55f916751858a210a2e02a06b6
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Mar 30 11:36:58 2012 +0200

    media-keys: Get the environment from gnome-keyring
    
    When launching custom applications.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=662528

 plugins/media-keys/gsd-media-keys-manager.c |   63 ++++++++++++++++++++++++++-
 1 files changed, 62 insertions(+), 1 deletions(-)
---
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index c809022..bdef10d 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -66,6 +66,10 @@
 #define GNOME_SESSION_DBUS_PATH "/org/gnome/SessionManager"
 #define GNOME_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
 
+#define GNOME_KEYRING_DBUS_NAME "org.gnome.keyring"
+#define GNOME_KEYRING_DBUS_PATH "/org/gnome/keyring/daemon"
+#define GNOME_KEYRING_DBUS_INTERFACE "org.gnome.keyring.Daemon"
+
 #define CUSTOM_BINDING_SCHEMA SETTINGS_BINDING_DIR ".custom-keybinding"
 
 static const gchar introspection_xml[] =
@@ -228,6 +232,57 @@ get_term_command (GsdMediaKeysManager *manager)
         return cmd;
 }
 
+static char **
+get_keyring_env (GsdMediaKeysManager *manager)
+{
+	GError *error = NULL;
+	GVariant *variant, *item;
+	GVariantIter *iter;
+	char **envp;
+
+	variant = g_dbus_connection_call_sync (manager->priv->connection,
+					       GNOME_KEYRING_DBUS_NAME,
+					       GNOME_KEYRING_DBUS_PATH,
+					       GNOME_KEYRING_DBUS_INTERFACE,
+					       "GetEnvironment",
+					       NULL,
+					       NULL,
+					       G_DBUS_CALL_FLAGS_NONE,
+					       -1,
+					       NULL,
+					       &error);
+	if (variant == NULL) {
+		g_warning ("Failed to call GetEnvironment on keyring daemon: %s", error->message);
+		g_error_free (error);
+		return NULL;
+	}
+
+	envp = g_get_environ ();
+
+	g_variant_get (variant, "(a{ss})", &iter);
+
+	while ((item = g_variant_iter_next_value (iter))) {
+		char *key;
+		char *value;
+
+		g_variant_get (item,
+			       "{ss}",
+			       &key,
+			       &value);
+
+		envp = g_environ_setenv (envp, key, value, TRUE);
+
+		g_variant_unref (item);
+		g_free (key);
+		g_free (value);
+	}
+
+	g_variant_iter_free (iter);
+	g_variant_unref (variant);
+
+	return envp;
+}
+
 static void
 execute (GsdMediaKeysManager *manager,
          char                *cmd,
@@ -253,15 +308,21 @@ execute (GsdMediaKeysManager *manager,
         }
 
         if (g_shell_parse_argv (exec, &argc, &argv, NULL)) {
+		char   **envp;
+
+		envp = get_keyring_env (manager);
+
                 retval = g_spawn_async (g_get_home_dir (),
                                         argv,
-                                        NULL,
+                                        envp,
                                         G_SPAWN_SEARCH_PATH,
                                         NULL,
                                         NULL,
                                         NULL,
                                         &error);
+
                 g_strfreev (argv);
+                g_strfreev (envp);
         }
 
         if (retval == FALSE) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]