[Xfce4-commits] [xfce/exo] 01/01: Correctly import user env

noreply at xfce.org noreply at xfce.org
Wed Aug 17 03:33:21 CEST 2016


This is an automated email from the git hooks/post-receive script.

bluesabre pushed a commit to branch master
in repository xfce/exo.

commit f016e39ba009e3cfa66c82af9394cae7951e6916
Author: Sean Davis <smd.seandavis at gmail.com>
Date:   Tue Aug 16 21:33:15 2016 -0400

    Correctly import user env
---
 exo-helper/exo-helper.c | 20 ++++++++++++++------
 exo/exo-execute.c       | 21 +++++++++++++++------
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/exo-helper/exo-helper.c b/exo-helper/exo-helper.c
index ce5ef9e..14c941d 100644
--- a/exo-helper/exo-helper.c
+++ b/exo-helper/exo-helper.c
@@ -325,7 +325,12 @@ exo_helper_get_command (const ExoHelper *helper)
   return *helper->commands_with_parameter;
 }
 
-
+/* Set the DISPLAY variable, to be use by g_spawn_async. */
+static void
+set_environment (gchar *display)
+{
+  g_setenv ("DISPLAY", display, TRUE);
+}
 
 /**
  * exo_helper_execute:
@@ -352,7 +357,6 @@ exo_helper_execute (ExoHelper   *helper,
   GError       *err = NULL;
   gchar       **commands;
   gchar       **argv;
-  gchar       **envp;
   gchar        *command;
   gchar        *display;
   guint         n;
@@ -401,16 +405,20 @@ exo_helper_execute (ExoHelper   *helper,
         continue;
 
       /* set the display variable */
-      envp = g_get_environ ();
       display = gdk_screen_make_display_name (screen);
-      envp = g_environ_setenv (envp, "DISPLAY", display, TRUE);
 
       /* try to run the command */
-      succeed = g_spawn_async (NULL, argv, envp, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, &err);
+      succeed = g_spawn_async (NULL,
+        argv,
+        NULL,
+        G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
+        (GSpawnChildSetupFunc) set_environment,
+        display,
+        &pid,
+        &err);
 
       /* cleanup */
       g_strfreev (argv);
-      g_strfreev (envp);
       g_free (display);
 
       /* check if the execution was successful */
diff --git a/exo/exo-execute.c b/exo/exo-execute.c
index 1fabf57..c7a756c 100644
--- a/exo/exo-execute.c
+++ b/exo/exo-execute.c
@@ -82,7 +82,12 @@ exo_execute_preferred_application (const gchar *category,
   return exo_execute_preferred_application_on_screen (category, parameter, working_directory, envp, gdk_screen_get_default (), error);
 }
 
-
+/* Set the DISPLAY variable, to be use by g_spawn_async. */
+static void
+set_environment (gchar *display)
+{
+  g_setenv ("DISPLAY", display, TRUE);
+}
 
 /**
  * exo_execute_preferred_application_on_screen:
@@ -119,13 +124,12 @@ gboolean
 exo_execute_preferred_application_on_screen (const gchar *category,
                                              const gchar *parameter,
                                              const gchar *working_directory,
-                                             gchar      **envp_in,
+                                             gchar      **envp,
                                              GdkScreen   *screen,
                                              GError     **error)
 {
   gchar   *argv[5];
   gchar   *display;
-  gchar  **envp = g_strdupv (envp_in);
   gint     argc = 0;
   gboolean success;
 
@@ -147,13 +151,18 @@ exo_execute_preferred_application_on_screen (const gchar *category,
 
   /* set the display environment variable */
   display = gdk_screen_make_display_name (screen);
-  envp = g_environ_setenv (envp, "DISPLAY", display, TRUE);
 
   /* launch the command */
-  success = g_spawn_async (working_directory, argv, envp, 0, NULL, NULL, NULL, error);
+  success = g_spawn_async (working_directory,
+    argv,
+    envp,
+    0,
+    (GSpawnChildSetupFunc) set_environment,
+    display,
+    NULL,
+    error);
 
   g_free (display);
-  g_strfreev (envp);
   return success;
 }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list