[vte] pty: spawn: Set PWD to the working directory to preserve symlinks
- From: Egmont Koblinger <egmontkob src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] pty: spawn: Set PWD to the working directory to preserve symlinks
- Date: Sat, 3 Feb 2018 17:56:08 +0000 (UTC)
commit fdaad997cd9d2fa56a9827f3c327aa192ea0abd9
Author: Egmont Koblinger <egmont gmail com>
Date: Sat Feb 3 18:55:02 2018 +0100
pty: spawn: Set PWD to the working directory to preserve symlinks
https://bugzilla.gnome.org/show_bug.cgi?id=758452
src/pty.cc | 10 +++++++++-
src/vtegtk.cc | 8 ++++++++
2 files changed, 17 insertions(+), 1 deletions(-)
---
diff --git a/src/pty.cc b/src/pty.cc
index 0c0b001..aa03c5a 100644
--- a/src/pty.cc
+++ b/src/pty.cc
@@ -256,6 +256,7 @@ vte_pty_child_setup (VtePty *pty)
*/
static gchar **
__vte_pty_merge_environ (char **envp,
+ const char *directory,
gboolean inherit)
{
GHashTable *table;
@@ -297,6 +298,13 @@ __vte_pty_merge_environ (char **envp,
/* Always set this ourself, not allowing replacing from envp */
g_hash_table_replace(table, g_strdup("COLORTERM"), g_strdup("truecolor"));
+ /* We need to put the working directory also in PWD, so that
+ * e.g. bash starts in the right directory if @directory is a symlink.
+ * See bug #502146 and #758452.
+ */
+ if (directory)
+ g_hash_table_replace(table, g_strdup("PWD"), g_strdup(directory));
+
array = g_ptr_array_sized_new (g_hash_table_size (table) + 1);
g_hash_table_iter_init(&iter, table);
while (g_hash_table_iter_next(&iter, (void**) &name, (void**) &value)) {
@@ -384,7 +392,7 @@ __vte_pty_spawn (VtePty *pty,
spawn_flags &= ~VTE_SPAWN_NO_PARENT_ENVV;
/* add the given environment to the childs */
- envp2 = __vte_pty_merge_environ (envv, inherit_envv);
+ envp2 = __vte_pty_merge_environ (envv, directory, inherit_envv);
_VTE_DEBUG_IF (VTE_DEBUG_MISC) {
g_printerr ("Spawning command:\n");
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index fc13517..8dd3d69 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -2459,6 +2459,10 @@ vte_terminal_watch_child (VteTerminal *terminal,
*
* See vte_pty_new(), g_spawn_async() and vte_terminal_watch_child() for more information.
*
+ * Beginning with 0.52, sets PWD to @working_directory in order to preserve symlink components.
+ * The caller should also make sure that symlinks were preserved while constructing the value of
@working_directory,
+ * e.g. by using vte_terminal_get_current_directory_uri(), g_get_current_dir() or get_current_dir_name().
+ *
* Returns: %TRUE on success, or %FALSE on error with @error filled in
*
* Deprecated: 0.48: Use vte_terminal_spawn_async() instead.
@@ -2626,6 +2630,10 @@ spawn_async_cb (GObject *source,
* in this case, if spawning was successful, the child process will be aborted
* automatically.
*
+ * Beginning with 0.52, sets PWD to @working_directory in order to preserve symlink components.
+ * The caller should also make sure that symlinks were preserved while constructing the value of
@working_directory,
+ * e.g. by using vte_terminal_get_current_directory_uri(), g_get_current_dir() or get_current_dir_name().
+ *
* Since: 0.48
*/
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]