[gnome-terminal] screen: Set PWD in the child environment



commit 760fbbd9340dac63b29436a3de411053456c8d2d
Author: Christian Persch <chpe gnome org>
Date:   Mon Jun 4 21:10:41 2012 +0200

    screen: Set PWD in the child environment
    
    Setting PWD is necessary so that e.g. bash starts in the right directory
    if the cwd is a symlink.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=502146

 src/terminal-screen.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index 49348a5..83dbc03 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -1273,6 +1273,7 @@ get_child_command (TerminalScreen *screen,
 
 static char**
 get_child_environment (TerminalScreen *screen,
+                       const char *cwd,
                        char **shell)
 {
   TerminalScreenPrivate *priv = screen->priv;
@@ -1338,6 +1339,12 @@ get_child_environment (TerminalScreen *screen,
 
   *shell = g_strdup (g_hash_table_lookup (env_table, "SHELL"));
 
+  /* We need to put the working directory also in PWD, so that
+   * e.g. bash starts in the right directory if @cwd is a symlink.
+   * See bug #502146.
+   */
+  g_hash_table_replace (env_table, g_strdup ("PWD"), g_strdup (cwd));
+
   g_hash_table_destroy (env_table);
   return (char **) g_ptr_array_free (retval, FALSE);
 }
@@ -1481,13 +1488,13 @@ terminal_screen_do_exec (TerminalScreen *screen,
 
   profile = priv->profile;
 
-  env = get_child_environment (screen, &shell);
-
   if (priv->initial_working_directory)
     working_dir = priv->initial_working_directory;
   else
     working_dir = g_get_home_dir ();
 
+  env = get_child_environment (screen, working_dir, &shell);
+
   if (!g_settings_get_boolean (profile, TERMINAL_PROFILE_LOGIN_SHELL_KEY))
     pty_flags |= VTE_PTY_NO_LASTLOG;
   if (!g_settings_get_boolean (profile, TERMINAL_PROFILE_UPDATE_RECORDS_KEY))



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