[vte/vte-next] 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-next] pty: Add a spwan flag to not inherit the parent environment
- Date: Sat, 8 Jun 2013 11:46:23 +0000 (UTC)
commit fa18cc48ca707a586dd4aa419b943920f5c85889
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/vtepty.h | 2 ++
2 files changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/src/pty.c b/src/pty.c
index 8b2536e..7efa810 100644
--- a/src/pty.c
+++ b/src/pty.c
@@ -367,13 +367,17 @@ vte_pty_child_setup (VtePty *pty)
/*
* __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;
@@ -384,13 +388,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++) {
@@ -464,6 +470,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;
@@ -475,8 +482,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/vtepty.h b/src/vtepty.h
index ccf9796..22cc3dc 100644
--- a/src/vtepty.h
+++ b/src/vtepty.h
@@ -57,6 +57,8 @@ typedef enum {
VTE_PTY_ERROR_PTY98_FAILED
} VtePtyError;
+#define VTE_SPAWN_NO_PARENT_ENVV (1 << 25)
+
GQuark vte_pty_error_quark (void);
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]