So, at some point when I was testing some of the recent keybindings I
introduced into tmux, I ran a separate tmux instance with "-L new" in a
new terminal, so I could test my changes. I typed "tmux list-bindings"
into the shell within this new server's session, and imagine my
confusion when I see a list of keybindings that didn't appear to include
the new ones I'd added. The reason, of course, is that the "tmux"
command always, always talks to the "default" server, regardless of what
$TMUX has to say about it: I have to explicitly type "tmux -L new
list-bindings", even though tmux ought to be able to figure out "-L new"
without my telling it. Stranger still, any attempt to run "tmux neww"
will fail with "can't establish current session", since it will try to
find what session we're running within _default_, by
pid-and-session-index information gleaned from $TMUX.
Thus, additional servers besides "default" have very much been
second-class citizens. Any value queries done from the shell (via the
"tmux" command) work great when you're in the "default" server, but will
fail or show erroneous information when you're in some other server.
This patch aims to remedy the situation, by using the path provided in
$TMUX when no other has been specified.
--
Micah J. Cowan
http://micah.cowan.name/
Index: tmux.c
===================================================================
--- tmux.c.orig
+++ tmux.c
@@ -47,7 +47,8 @@
__dead void usage(void);
void fill_session(struct msg_command_data *);
-char *makesockpath(const char *);
+char *path_from_env(void);
+char *xmakesockpath(const char *);
__dead void shell_exec(const char *, const char *);
struct imsgbuf *main_ibuf;
@@ -170,7 +171,27 @@
}
char *
-makesockpath(const char *label)
+path_from_env(void)
+{
+ char *env, *end, *new_path;
+ size_t len;
+
+ if ((env = getenv("TMUX")) == NULL)
+ return NULL;
+
+ if ((end = strchr(env, ',')) == NULL)
+ return NULL;
+
+ len = end - env;
+ new_path = xmalloc(len + 1);
+ memcpy(new_path, env, len);
+ new_path[len] = '\0';
+
+ return new_path;
+}
+
+char *
+xmakesockpath(const char *label)
{
char base[MAXPATHLEN], *path;
struct stat sb;
@@ -180,21 +201,25 @@
xsnprintf(base, MAXPATHLEN, "%s/tmux-%d", _PATH_TMP, uid);
if (mkdir(base, S_IRWXU) != 0 && errno != EEXIST)
- return (NULL);
+ goto error;
if (lstat(base, &sb) != 0)
- return (NULL);
+ goto error;
if (!S_ISDIR(sb.st_mode)) {
errno = ENOTDIR;
- return (NULL);
+ goto error;
}
if (sb.st_uid != uid || (sb.st_mode & (S_IRWXG|S_IRWXO)) != 0) {
errno = EACCES;
- return (NULL);
+ goto error;
}
xasprintf(&path, "%s/%s", base, label);
return (path);
+
+error:
+ log_warn("can't create socket");
+ exit(1);
}
__dead void
@@ -445,13 +470,18 @@
}
}
- if (label == NULL)
- label = xstrdup("default");
- if (path == NULL && (path = makesockpath(label)) == NULL) {
- log_warn("can't create socket");
- exit(1);
+ if (path == NULL) {
+ if (label == NULL) {
+ path = path_from_env();
+ if (path == NULL) {
+ path = xmakesockpath("default");
+ }
+ } else {
+ path = xmakesockpath(label);
+ }
}
- xfree(label);
+ if (label != NULL)
+ xfree(label);
if (shellcmd != NULL) {
msg = MSG_SHELL;
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users