[vte/vte-0-34] pty: Add a spwan flag to not inherit the parent environment
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/vte-0-34] pty: Add a spwan flag to not inherit the parent environment
- Date: Sat, 25 May 2013 16:05:43 +0000 (UTC)
commit 4ab8de471e5dea5f58873abd5cc4a24feaa7210b
Author: Christian Persch <chpe gnome org>
Date: Sat May 25 18:04:29 2013 +0200
pty: Add a spwan flag to not inherit the parent environment
In gnome-terminal we don't want the gnome-terminal-server's environment
to pollute the child environment, so add the VTE_SPAWN_NO_PARENT_ENVV flag
that when passed to vte_terminal_fork_command_full() makes it *not*
merge the parent's environment.
src/pty.c | 26 ++++++++++++++++++--------
src/vte.h | 2 ++
2 files changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/src/pty.c b/src/pty.c
index b0b0be4..5c6afd5 100644
--- a/src/pty.c
+++ b/src/pty.c
@@ -412,13 +412,17 @@ __vte_pty_get_argv (const char *command,
/*
* __vte_pty_merge_environ:
* @envp: environment vector
+ * @term_value: the value for the TERM env variable, or %NULL
+ * @inherit: whether to use the parent environment
*
* Merges @envp to the parent environment, and returns a new environment vector.
*
* Returns: a newly allocated string array. Free using g_strfreev()
*/
static gchar **
-__vte_pty_merge_environ (char **envp, const char *term_value)
+__vte_pty_merge_environ (char **envp,
+ const char *term_value,
+ gboolean inherit)
{
GHashTable *table;
GHashTableIter iter;
@@ -429,13 +433,15 @@ __vte_pty_merge_environ (char **envp, const char *term_value)
table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
- parent_environ = g_listenv ();
- for (i = 0; parent_environ[i] != NULL; i++) {
- g_hash_table_replace (table,
- g_strdup (parent_environ[i]),
- g_strdup (g_getenv (parent_environ[i])));
+ if (inherit) {
+ parent_environ = g_listenv ();
+ for (i = 0; parent_environ[i] != NULL; i++) {
+ g_hash_table_replace (table,
+ g_strdup (parent_environ[i]),
+ g_strdup (g_getenv (parent_environ[i])));
+ }
+ g_strfreev (parent_environ);
}
- g_strfreev (parent_environ);
if (envp != NULL) {
for (i = 0; envp[i] != NULL; i++) {
@@ -537,6 +543,7 @@ __vte_pty_spawn (VtePty *pty,
VtePtyPrivate *priv = pty->priv;
VtePtyChildSetupData *data = &priv->child_setup_data;
gboolean ret = TRUE;
+ gboolean inherit_envv;
char **envp2;
gint i;
GError *err = NULL;
@@ -548,8 +555,11 @@ __vte_pty_spawn (VtePty *pty,
*/
spawn_flags &= ~G_SPAWN_LEAVE_DESCRIPTORS_OPEN;
+ inherit_envv = (spawn_flags & VTE_SPAWN_NO_PARENT_ENVV) == 0;
+ spawn_flags &= ~VTE_SPAWN_NO_PARENT_ENVV;
+
/* add the given environment to the childs */
- envp2 = __vte_pty_merge_environ (envv, pty->priv->term);
+ envp2 = __vte_pty_merge_environ (envv, pty->priv->term, inherit_envv);
_VTE_DEBUG_IF (VTE_DEBUG_MISC) {
g_printerr ("Spawing command:\n");
diff --git a/src/vte.h b/src/vte.h
index 35fb0f4..b4bf0fb 100644
--- a/src/vte.h
+++ b/src/vte.h
@@ -269,6 +269,8 @@ VtePty *vte_terminal_pty_new (VteTerminal *terminal,
void vte_terminal_watch_child (VteTerminal *terminal,
GPid child_pid);
+#define VTE_SPAWN_NO_PARENT_ENVV (1 << 25)
+
gboolean vte_terminal_fork_command_full(VteTerminal *terminal,
VtePtyFlags pty_flags,
const char *working_directory,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]