[gnome-builder] subprocess: implement clear-env for standard subprocesses



commit 2269dee6b6e2323fd96a27e76582a3c728a68559
Author: Christian Hergert <chergert redhat com>
Date:   Wed Sep 14 01:15:05 2016 -0700

    subprocess: implement clear-env for standard subprocesses
    
    When we just use GSubprocess, we need to implement clear-env ourselves so
    that we inherit when necessary.

 libide/subprocess/ide-subprocess-launcher.c |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)
---
diff --git a/libide/subprocess/ide-subprocess-launcher.c b/libide/subprocess/ide-subprocess-launcher.c
index 78dc2e3..be8eab0 100644
--- a/libide/subprocess/ide-subprocess-launcher.c
+++ b/libide/subprocess/ide-subprocess-launcher.c
@@ -242,8 +242,30 @@ ide_subprocess_launcher_spawn_worker (GTask        *task,
   launcher = g_subprocess_launcher_new (priv->flags);
   g_subprocess_launcher_set_child_setup (launcher, child_setup_func, NULL, NULL);
   g_subprocess_launcher_set_cwd (launcher, priv->cwd);
+
   if (priv->environ->len > 1)
-    g_subprocess_launcher_set_environ (launcher, (gchar **)priv->environ->pdata);
+    {
+      g_auto(GStrv) env = NULL;
+
+      if (!priv->clear_env)
+        env = g_strdupv (g_get_environ ());
+
+      for (guint i = 0; i < (priv->environ->len - 1); i++)
+        {
+          const gchar *pair = g_ptr_array_index (priv->environ, i);
+          const gchar *eq = strchr (pair, '=');
+          const gchar *val = eq ? eq + 1 : NULL;
+
+          if (pair && eq && val)
+            {
+              g_autofree gchar *key = g_strndup (pair, eq - pair);
+              env = g_environ_setenv (env, key, val, TRUE);
+            }
+        }
+
+      g_subprocess_launcher_set_environ (launcher, env);
+    }
+
   real = g_subprocess_launcher_spawnv (launcher,
                                        (const gchar * const *)priv->argv->pdata,
                                        &error);


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