[gnome-builder] subprocess: set environ for breakout subprocess



commit ebe177669045629cfa46fcbf60dd36e296a4a92c
Author: Christian Hergert <chergert redhat com>
Date:   Sun Mar 12 18:23:07 2017 -0700

    subprocess: set environ for breakout subprocess
    
    When executing a process through the subprocess helper, we still need to
    ensure some basic params are set. This promotes the setting of these
    variables to the spawn vfunc so they apply to both gsubprocess/breakout.
    
    Additionally, we rely on the chain ordering so that flatpak subprocess
    launcher can set /app/bin into the path without this overriding.

 libide/subprocess/ide-subprocess-launcher.c       |   24 +++++++++++++-------
 plugins/flatpak/gbp-flatpak-subprocess-launcher.c |    4 +++
 2 files changed, 19 insertions(+), 9 deletions(-)
---
diff --git a/libide/subprocess/ide-subprocess-launcher.c b/libide/subprocess/ide-subprocess-launcher.c
index 4028f8a..bffe1f1 100644
--- a/libide/subprocess/ide-subprocess-launcher.c
+++ b/libide/subprocess/ide-subprocess-launcher.c
@@ -269,15 +269,6 @@ ide_subprocess_launcher_spawn_worker (GTask        *task,
 
   g_return_if_fail (IDE_IS_SUBPROCESS_LAUNCHER (self));
 
-  /* Many things break without at least PATH, HOME, etc. being set */
-  if (priv->clear_env)
-    {
-      ide_subprocess_launcher_setenv (self, "PATH", "/bin:/usr/bin", FALSE);
-      ide_subprocess_launcher_setenv (self, "HOME", g_get_home_dir (), FALSE);
-      ide_subprocess_launcher_setenv (self, "USER", g_get_user_name (), FALSE);
-      ide_subprocess_launcher_setenv (self, "LANG", g_getenv ("LANG"), FALSE);
-    }
-
   {
     g_autofree gchar *str = NULL;
     g_autofree gchar *env = NULL;
@@ -386,6 +377,7 @@ ide_subprocess_launcher_real_spawn (IdeSubprocessLauncher  *self,
                                     GCancellable           *cancellable,
                                     GError                **error)
 {
+  IdeSubprocessLauncherPrivate *priv = ide_subprocess_launcher_get_instance_private (self);
   g_autoptr(GTask) task = NULL;
 
   g_assert (IDE_IS_SUBPROCESS_LAUNCHER (self));
@@ -394,6 +386,20 @@ ide_subprocess_launcher_real_spawn (IdeSubprocessLauncher  *self,
   task = g_task_new (self, cancellable, NULL, NULL);
   g_task_set_source_tag (task, ide_subprocess_launcher_real_spawn);
 
+  if (priv->clear_env)
+    {
+      /*
+       * Many things break without at least PATH, HOME, etc. being set.
+       * The GbpFlatpakSubprocessLauncher will also try to set PATH so
+       * that it can get /app/bin too. Since it chains up to us, we wont
+       * overwrite PATH in that case (which is what we want).
+       */
+      ide_subprocess_launcher_setenv (self, "PATH", "/bin:/usr/bin", FALSE);
+      ide_subprocess_launcher_setenv (self, "HOME", g_get_home_dir (), FALSE);
+      ide_subprocess_launcher_setenv (self, "USER", g_get_user_name (), FALSE);
+      ide_subprocess_launcher_setenv (self, "LANG", g_getenv ("LANG"), FALSE);
+    }
+
   if (should_use_breakout_process (self))
     g_task_run_in_thread_sync (task, ide_subprocess_launcher_spawn_host_worker);
   else
diff --git a/plugins/flatpak/gbp-flatpak-subprocess-launcher.c 
b/plugins/flatpak/gbp-flatpak-subprocess-launcher.c
index cf1d9e9..a350661 100644
--- a/plugins/flatpak/gbp-flatpak-subprocess-launcher.c
+++ b/plugins/flatpak/gbp-flatpak-subprocess-launcher.c
@@ -79,6 +79,10 @@ gbp_flatpak_subprocess_launcher_spawn (IdeSubprocessLauncher  *launcher,
             }
         }
 
+      /*
+       * Since this can be called multiple times, we have to avoid re-adding
+       * the --env= parameters a second (or third, or fourth) time.
+       */
       for (guint i = 0; envp[i] != NULL; i++)
         {
           g_autofree gchar *arg = g_strdup_printf ("--env=%s", envp[i]);


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