Ubuntu Pastebin

Paste from Marco Trevisan (3v1n0) at Thu, 28 Apr 2016 09:22:27 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Index: gnome-session-3.18.1.2/gnome-session/gsm-util.c
===================================================================
--- gnome-session-3.18.1.2.orig/gnome-session/gsm-util.c
+++ gnome-session-3.18.1.2/gnome-session/gsm-util.c
@@ -491,6 +491,52 @@ gsm_util_update_activation_environment (
         return environment_updated;
 }
 
+static gboolean
+gsm_util_update_upstart_environment (const char  *variable,
+                                     const char  *value,
+                                     GError     **error)
+{
+        GDBusConnection *connection;
+        gboolean         environment_updated;
+        GVariant        *reply;
+        GError          *bus_error = NULL;
+        gchar           *environment_string;
+
+        environment_updated = FALSE;
+        connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
+
+        if (connection == NULL) {
+                return FALSE;
+        }
+
+        environment_string = g_strdup_printf ("%s=%s", variable, value);
+        reply = g_dbus_connection_call_sync (connection,
+                                             "com.ubuntu.Upstart",
+                                             "/com/ubuntu/Upstart",
+                                             "com.ubuntu.Upstart0_6",
+                                             "SetEnv",
+                                             g_variant_new ("(@assb)",
+                                                            g_variant_new_array (G_VARIANT_TYPE_STRING, NULL, 0),
+                                                            environment_string,
+                                                            TRUE),
+                                             NULL,
+                                             G_DBUS_CALL_FLAGS_NONE,
+                                             -1, NULL, &bus_error);
+
+
+        if (bus_error != NULL) {
+                g_propagate_error (error, bus_error);
+        } else {
+                environment_updated = TRUE;
+                g_variant_unref (reply);
+        }
+
+        g_clear_object (&connection);
+        g_free (environment_string);
+
+        return environment_updated;
+}
+
 void
 gsm_util_setenv (const char *variable,
                  const char *value)
@@ -509,6 +555,13 @@ gsm_util_setenv (const char *variable,
          */
         if (!gsm_util_update_activation_environment (variable, value, &bus_error)) {
                 g_warning ("Could not make bus activated clients aware of %s=%s environment variable: %s", variable, value, bus_error->message);
-                g_error_free (bus_error);
+                g_clear_error (&bus_error);
+        }
+
+        if (g_getenv ("UPSTART_SESSION") != NULL) {
+                if (!gsm_util_update_upstart_environment (variable, value, &bus_error)) {
+                        g_warning ("Could not make upstart activated jobs aware of %s=%s environment variable: %s", variable, value, bus_error->message);
+                        g_clear_error (&bus_error);
+                }
         }
 }
Download as text