diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2022-09-26 17:09:33 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2022-10-02 18:11:16 +0000 |
| commit | 90ce4f3008a7c7f01dcdee4504b9c512c96a41d1 (patch) | |
| tree | 106f2a1b25b4eed78141bba802470f624a778917 /client.c | |
| parent | slave: spawn: set PWD environment variable (diff) | |
main/client: use $PWD for cwd, when $PWD is valid
If $PWD is set, and its resolved path matches the *actual* working
directory, use $PWD for cwd when instantiating the terminal.
This makes a difference when $PWD refers to a symlink; before this
patch, we’d instantiate the terminal in the *resolved* path. Now it’ll
use the symlink instead.
Diffstat (limited to 'client.c')
| -rw-r--r-- | client.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -408,6 +408,28 @@ main(int argc, char *const *argv) cwd = _cwd; } + const char *pwd = getenv("PWD"); + if (pwd != NULL) { + char *resolved_path_cwd = realpath(cwd, NULL); + char *resolved_path_pwd = realpath(pwd, NULL); + + if (resolved_path_cwd != NULL && + resolved_path_pwd != NULL && + strcmp(resolved_path_cwd, resolved_path_pwd) == 0) + { + /* + * The resolved path of $PWD matches the resolved path of + * the *actual* working directory - use $PWD. + * + * This makes a difference when $PWD refers to a symlink. + */ + cwd = pwd; + } + + free(resolved_path_cwd); + free(resolved_path_pwd); + } + if (client_environment) { for (char **e = environ; *e != NULL; e++) { if (!push_string(&envp, *e, &total_len)) |
