|
1 |
From f016e39ba009e3cfa66c82af9394cae7951e6916 Mon Sep 17 00:00:00 2001 |
|
2 |
From: Sean Davis <smd.seandavis@gmail.com> |
|
3 |
Date: Tue, 16 Aug 2016 21:33:15 -0400 |
|
4 |
Subject: Correctly import user env |
|
5 |
|
|
6 |
|
|
7 |
diff --git a/exo-helper/exo-helper.c b/exo-helper/exo-helper.c |
|
8 |
index ce5ef9e..14c941d 100644 |
|
9 |
--- a/exo-helper/exo-helper.c |
|
10 |
+++ b/exo-helper/exo-helper.c |
|
11 |
@@ -325,7 +325,12 @@ exo_helper_get_command (const ExoHelper *helper) |
|
12 |
return *helper->commands_with_parameter; |
|
13 |
} |
|
14 |
|
|
15 |
- |
|
16 |
+/* Set the DISPLAY variable, to be use by g_spawn_async. */ |
|
17 |
+static void |
|
18 |
+set_environment (gchar *display) |
|
19 |
+{ |
|
20 |
+ g_setenv ("DISPLAY", display, TRUE); |
|
21 |
+} |
|
22 |
|
|
23 |
/** |
|
24 |
* exo_helper_execute: |
|
25 |
@@ -352,7 +357,6 @@ exo_helper_execute (ExoHelper *helper, |
|
26 |
GError *err = NULL; |
|
27 |
gchar **commands; |
|
28 |
gchar **argv; |
|
29 |
- gchar **envp; |
|
30 |
gchar *command; |
|
31 |
gchar *display; |
|
32 |
guint n; |
|
33 |
@@ -401,16 +405,20 @@ exo_helper_execute (ExoHelper *helper, |
|
34 |
continue; |
|
35 |
|
|
36 |
/* set the display variable */ |
|
37 |
- envp = g_get_environ (); |
|
38 |
display = gdk_screen_make_display_name (screen); |
|
39 |
- envp = g_environ_setenv (envp, "DISPLAY", display, TRUE); |
|
40 |
|
|
41 |
/* try to run the command */ |
|
42 |
- succeed = g_spawn_async (NULL, argv, envp, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, &err); |
|
43 |
+ succeed = g_spawn_async (NULL, |
|
44 |
+ argv, |
|
45 |
+ NULL, |
|
46 |
+ G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, |
|
47 |
+ (GSpawnChildSetupFunc) set_environment, |
|
48 |
+ display, |
|
49 |
+ &pid, |
|
50 |
+ &err); |
|
51 |
|
|
52 |
/* cleanup */ |
|
53 |
g_strfreev (argv); |
|
54 |
- g_strfreev (envp); |
|
55 |
g_free (display); |
|
56 |
|
|
57 |
/* check if the execution was successful */ |
|
58 |
diff --git a/exo/exo-execute.c b/exo/exo-execute.c |
|
59 |
index 1fabf57..c7a756c 100644 |
|
60 |
--- a/exo/exo-execute.c |
|
61 |
+++ b/exo/exo-execute.c |
|
62 |
@@ -82,7 +82,12 @@ exo_execute_preferred_application (const gchar *category, |
|
63 |
return exo_execute_preferred_application_on_screen (category, parameter, working_directory, envp, gdk_screen_get_default (), error); |
|
64 |
} |
|
65 |
|
|
66 |
- |
|
67 |
+/* Set the DISPLAY variable, to be use by g_spawn_async. */ |
|
68 |
+static void |
|
69 |
+set_environment (gchar *display) |
|
70 |
+{ |
|
71 |
+ g_setenv ("DISPLAY", display, TRUE); |
|
72 |
+} |
|
73 |
|
|
74 |
/** |
|
75 |
* exo_execute_preferred_application_on_screen: |
|
76 |
@@ -119,13 +124,12 @@ gboolean |
|
77 |
exo_execute_preferred_application_on_screen (const gchar *category, |
|
78 |
const gchar *parameter, |
|
79 |
const gchar *working_directory, |
|
80 |
- gchar **envp_in, |
|
81 |
+ gchar **envp, |
|
82 |
GdkScreen *screen, |
|
83 |
GError **error) |
|
84 |
{ |
|
85 |
gchar *argv[5]; |
|
86 |
gchar *display; |
|
87 |
- gchar **envp = g_strdupv (envp_in); |
|
88 |
gint argc = 0; |
|
89 |
gboolean success; |
|
90 |
|
|
91 |
@@ -147,13 +151,18 @@ exo_execute_preferred_application_on_screen (const gchar *category, |
|
92 |
|
|
93 |
/* set the display environment variable */ |
|
94 |
display = gdk_screen_make_display_name (screen); |
|
95 |
- envp = g_environ_setenv (envp, "DISPLAY", display, TRUE); |
|
96 |
|
|
97 |
/* launch the command */ |
|
98 |
- success = g_spawn_async (working_directory, argv, envp, 0, NULL, NULL, NULL, error); |
|
99 |
+ success = g_spawn_async (working_directory, |
|
100 |
+ argv, |
|
101 |
+ envp, |
|
102 |
+ 0, |
|
103 |
+ (GSpawnChildSetupFunc) set_environment, |
|
104 |
+ display, |
|
105 |
+ NULL, |
|
106 |
+ error); |
|
107 |
|
|
108 |
g_free (display); |
|
109 |
- g_strfreev (envp); |
|
110 |
return success; |
|
111 |
} |
|
112 |
|
|
113 |
-- |
|
114 |
cgit v0.10.1 |
|
115 |
|