diff options
author | 2018-11-22 10:36:40 +0000 | |
---|---|---|
committer | 2018-11-22 10:36:40 +0000 | |
commit | ca2738ca54e90bb90b98aa1e094923e07397b78d (patch) | |
tree | 03eea4e1858148f2ccb205e875952ea9f474a74a /usr.bin/tmux/tmux.c | |
parent | Output info on SIGUSR1 as well as SIGINFO to resync with portable. (diff) | |
download | wireguard-openbsd-ca2738ca54e90bb90b98aa1e094923e07397b78d.tar.xz wireguard-openbsd-ca2738ca54e90bb90b98aa1e094923e07397b78d.zip |
Do not use PWD unless it actually matches the real working directory.
Diffstat (limited to 'usr.bin/tmux/tmux.c')
-rw-r--r-- | usr.bin/tmux/tmux.c | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c index 84d801c7951..b12fda88cd6 100644 --- a/usr.bin/tmux/tmux.c +++ b/usr.bin/tmux/tmux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.c,v 1.186 2018/01/12 10:22:02 nicm Exp $ */ +/* $OpenBSD: tmux.c,v 1.187 2018/11/22 10:36:40 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -167,6 +167,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; @@ -191,7 +216,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); |