summaryrefslogtreecommitdiffstats
path: root/tmux.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2018-11-22 12:02:38 +0000
committerThomas Adam <thomas@xteddy.org>2018-11-22 12:02:38 +0000
commit2977317243eac07f819190a38f74da24bfa1b741 (patch)
tree35dcb4be286ac4e0ecafd78a2ae1127ef8ca1c8f /tmux.c
parent2eca63b98e21a4e76d77dedf339da42f7291cc76 (diff)
parent3a7b9d57355c4b2b521f05049a5c6f5eb2939b5d (diff)
Merge branch 'obsd-master'
Diffstat (limited to 'tmux.c')
-rw-r--r--tmux.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/tmux.c b/tmux.c
index 5b73079e..f4265e0a 100644
--- a/tmux.c
+++ b/tmux.c
@@ -164,6 +164,31 @@ setblocking(int fd, int state)
}
const char *
+find_cwd(void)
+{
+ char resolved1[PATH_MAX], resolved2[PATH_MAX];
+ static char cwd[PATH_MAX];
+ const char *pwd;
+
+ if (getcwd(cwd, sizeof cwd) == NULL)
+ return (NULL);
+ if ((pwd = getenv("PWD")) == NULL || *pwd == '\0')
+ return (cwd);
+
+ /*
+ * We want to use PWD so that symbolic links are maintained,
+ * but only if it matches the actual working directory.
+ */
+ if (realpath(pwd, resolved1) == NULL)
+ return (cwd);
+ if (realpath(cwd, resolved2) == NULL)
+ return (cwd);
+ if (strcmp(resolved1, resolved2) != 0)
+ return (cwd);
+ return (pwd);
+}
+
+const char *
find_home(void)
{
struct passwd *pw;
@@ -188,7 +213,6 @@ int
main(int argc, char **argv)
{
char *path, *label, *cause, **var;
- char tmp[PATH_MAX];
const char *s, *shell, *cwd;
int opt, flags, keys;
const struct options_table_entry *oe;
@@ -293,8 +317,7 @@ main(int argc, char **argv)
global_environ = environ_create();
for (var = environ; *var != NULL; var++)
environ_put(global_environ, *var);
- if ((cwd = getenv("PWD")) == NULL &&
- (cwd = getcwd(tmp, sizeof tmp)) != NULL)
+ if ((cwd = find_cwd()) != NULL)
environ_set(global_environ, "PWD", "%s", cwd);
global_options = options_create(NULL);