summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2017-11-28 23:27:57 -0500
committerMatthias Clasen <mclasen@redhat.com>2017-12-17 17:33:02 -0500
commit5f022cbc129771623a612773d975058748f4ea72 (patch)
treef6a2ca3a4ce4090182aead4f8184b415c8253a99
parenta41e0ce4a4990da9b9ed8bcd7393a4b6e23f8eb0 (diff)
downloadgtk+-5f022cbc129771623a612773d975058748f4ea72.tar.gz
Avoid calling unsetenv too late
Stash the DESKTOP_AUTOSTART_ID env var in a constructor, before any threads have been created. https://bugzilla.gnome.org/show_bug.cgi?id=790963
-rw-r--r--gtk/gtkapplication-dbus.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/gtk/gtkapplication-dbus.c b/gtk/gtkapplication-dbus.c
index be88565216..0b052757b5 100644
--- a/gtk/gtkapplication-dbus.c
+++ b/gtk/gtkapplication-dbus.c
@@ -148,18 +148,44 @@ gtk_application_get_proxy_if_service_present (GDBusConnection *connection,
return proxy;
}
+#ifdef G_HAS_CONSTRUCTORS
+#ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
+#pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(stash_desktop_autostart_id)
+#endif
+G_DEFINE_CONSTRUCTOR(stash_desktop_autostart_id)
+#endif
+
+static char *client_id = NULL;
+
+static void
+stash_desktop_autostart_id (void)
+{
+ const char *desktop_autostart_id;
+
+ desktop_autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID");
+ client_id = g_strdup (desktop_autostart_id ? desktop_autostart_id : "");
+
+ /* Unset DESKTOP_AUTOSTART_ID in order to avoid child processes to
+ * use the same client id.
+ */
+ g_unsetenv ("DESKTOP_AUTOSTART_ID");
+}
+
static void
gtk_application_impl_dbus_startup (GtkApplicationImpl *impl,
gboolean register_session)
{
GtkApplicationImplDBus *dbus = (GtkApplicationImplDBus *) impl;
- static gchar *client_id;
GError *error = NULL;
GVariant *res;
gboolean same_bus;
const char *bus_name;
const char *client_interface;
+#ifndef G_HAS_CONSTRUCTORS
+ stash_desktop_autostart_id ();
+#endif
+
dbus->session = g_application_get_dbus_connection (G_APPLICATION (impl->application));
if (!dbus->session)
@@ -169,18 +195,6 @@ gtk_application_impl_dbus_startup (GtkApplicationImpl *impl,
dbus->object_path = g_application_get_dbus_object_path (G_APPLICATION (impl->application));
dbus->unique_name = g_dbus_connection_get_unique_name (dbus->session);
- if (client_id == NULL)
- {
- const gchar *desktop_autostart_id;
-
- desktop_autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID");
- /* Unset DESKTOP_AUTOSTART_ID in order to avoid child processes to
- * use the same client id.
- */
- g_unsetenv ("DESKTOP_AUTOSTART_ID");
- client_id = g_strdup (desktop_autostart_id ? desktop_autostart_id : "");
- }
-
g_debug ("Connecting to session manager");
/* Try the GNOME session manager first */