aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2012-11-26 11:35:28 +0000
committerNicholas Marriott <nicm@openbsd.org>2012-11-26 11:35:28 +0000
commitd762ced298c35d58524433cacb08c5d0a7364f96 (patch)
tree7f731c0c5f69987139fd0e88554083ab8503630a
parent260419f48efccd1ca80cd00168ef2471e765e8b6 (diff)
downloadrtmux-d762ced298c35d58524433cacb08c5d0a7364f96.tar.gz
rtmux-d762ced298c35d58524433cacb08c5d0a7364f96.tar.bz2
rtmux-d762ced298c35d58524433cacb08c5d0a7364f96.zip
Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case realpath is allowed to fail. From Romain Francoise.
-rw-r--r--tmux.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/tmux.c b/tmux.c
index e01017c9..7bce10ec 100644
--- a/tmux.c
+++ b/tmux.c
@@ -159,7 +159,7 @@ parseenvironment(void)
char *
makesocketpath(const char *label)
{
- char base[MAXPATHLEN], *path, *s;
+ char base[MAXPATHLEN], realbase[MAXPATHLEN], *path, *s;
struct stat sb;
u_int uid;
@@ -183,7 +183,10 @@ makesocketpath(const char *label)
return (NULL);
}
- xasprintf(&path, "%s/%s", base, label);
+ if (realpath(base, realbase) == NULL)
+ strlcpy(realbase, base, sizeof realbase);
+
+ xasprintf(&path, "%s/%s", realbase, label);
return (path);
}
@@ -384,8 +387,7 @@ main(int argc, char **argv)
}
}
free(label);
- if (realpath(path, socket_path) == NULL)
- strlcpy(socket_path, path, sizeof socket_path);
+ strlcpy(socket_path, path, sizeof socket_path);
free(path);
/* Set process title. */