From: "Jan Alexander Steffens (heftig)" Date: Fri, 25 Dec 2020 18:01:12 +0100 Subject: screen: Manually handle env inheritance Don't let VTE handle merging the environment; build the merged block ourselves. This avoids confusion when we reuse the exec data. Bug: https://gitlab.gnome.org/GNOME/gnome-terminal/-/issues/303 Bug-Debian: https://bugs.debian.org/973918 Origin: upstream, 3.39.0, commit:aa45ba5c83d8e8940dc20e24397dc4475a72441d --- src/terminal-screen.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/terminal-screen.c b/src/terminal-screen.c index 0e447ae..10d052f 100644 --- a/src/terminal-screen.c +++ b/src/terminal-screen.c @@ -946,9 +946,7 @@ terminal_screen_exec (TerminalScreen *screen, &shell); gboolean preserve_cwd = FALSE; - GSpawnFlags spawn_flags = G_SPAWN_SEARCH_PATH_FROM_ENVP; - if (initial_envv) - spawn_flags |= VTE_SPAWN_NO_PARENT_ENVV; + GSpawnFlags spawn_flags = G_SPAWN_SEARCH_PATH_FROM_ENVP | VTE_SPAWN_NO_PARENT_ENVV; gs_strfreev char **exec_argv = NULL; if (!terminal_screen_get_child_command (screen, argv, @@ -1435,6 +1433,7 @@ terminal_screen_get_child_environment (TerminalScreen *screen, { TerminalApp *app = terminal_app_get (); char **env; + gs_strfreev char** current_environ = NULL; char *e, *v; GHashTable *env_table; GHashTableIter iter; @@ -1443,17 +1442,21 @@ terminal_screen_get_child_environment (TerminalScreen *screen, env_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - env = initial_envv; - if (env) + if (initial_envv) + env = initial_envv; + else { + env = current_environ = g_get_environ (); + /* Remove this variable which we set in server.c:main() */ + env = g_environ_unsetenv (env, "G_ENABLE_DIAGNOSTIC"); + } + + for (i = 0; env[i]; ++i) { - for (i = 0; env[i]; ++i) - { - v = strchr (env[i], '='); - if (v) - g_hash_table_replace (env_table, g_strndup (env[i], v - env[i]), g_strdup (v + 1)); - else - g_hash_table_replace (env_table, g_strdup (env[i]), NULL); - } + v = strchr (env[i], '='); + if (v) + g_hash_table_replace (env_table, g_strndup (env[i], v - env[i]), g_strdup (v + 1)); + else + g_hash_table_replace (env_table, g_strdup (env[i]), NULL); } /* Remove unwanted env variables */