When tmux starts for the very first time we call realpath() on a socket path that doesn't exist yet, the server hasn't started so the socket hasn't been created. On Linux at least, this fails with ENOENT and leaves the path unchanged, so it can contain a double slash (e.g. /tmp//tmux-uid/label).
This is usually not an issue, except that it makes the client nesting check fail: realpath() works in the nested client (because by then the socket exists), removing the double slash, and the paths are compared with strcmp(). So you can mistakenly attach to the same tmux session from within tmux, which has strange results. To avoid this, canonicalize the socket directory, not the full path. We're sure that it exists since we just created it (or checked that it's correct). diff --git a/tmux.c b/tmux.c index 5a773f6..f685660 100644 --- a/tmux.c +++ b/tmux.c @@ -162,7 +162,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; @@ -186,7 +186,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); } @@ -390,8 +393,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); #ifdef HAVE_SETPROCTITLE ------------------------------------------------------------------------------ Monitor your physical, virtual and cloud infrastructure from a single web console. Get in-depth insight into apps, servers, databases, vmware, SAP, cloud infrastructure, etc. Download 30-day Free Trial. Pricing starts from $795 for 25 servers or applications! http://p.sf.net/sfu/zoho_dev2dev_nov _______________________________________________ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users