Put socket path in $TMUX.

This commit is contained in:
Nicholas Marriott 2009-03-04 17:24:07 +00:00
parent 171256057e
commit 65b9aeb337
7 changed files with 54 additions and 44 deletions

1
TODO
View File

@ -81,7 +81,6 @@
- attach should have a flag to create session if it doesn't exist
- swap-pane-up, swap-pane-down (maybe move-pane-*)
- move-pane (to window) (maybe break-pane?)
- $TMUX should contain socket path
- 88 colour support; new grid cell flag, and 256<->88 88<->16 translation tables
- some fix for SF feature request 2527847 - now remain-by-default has gone
cannot control it per-session

View File

@ -1,4 +1,4 @@
/* $Id: client-fn.c,v 1.5 2009-01-10 14:43:43 nicm Exp $ */
/* $Id: client-fn.c,v 1.6 2009-03-04 17:24:07 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,29 +26,39 @@
void
client_fill_session(struct msg_command_data *data)
{
char *env, *ptr, buf[256];
char *env, *ptr1, *ptr2, buf[256];
size_t len;
const char *errstr;
long long ll;
data->pid = -1;
if ((env = getenv("TMUX")) == NULL)
return;
if ((ptr = strchr(env, ',')) == NULL)
return;
if ((size_t) (ptr - env) > sizeof buf)
return;
memcpy(buf, env, ptr - env);
buf[ptr - env] = '\0';
ll = strtonum(ptr + 1, 0, UINT_MAX, &errstr);
if (errstr != NULL)
if ((ptr2 = strrchr(env, ',')) == NULL || ptr2 == env)
return;
data->idx = ll;
for (ptr1 = ptr2 - 1; ptr1 > env && *ptr1 != ','; ptr1--)
;
if (*ptr1 != ',')
return;
ptr1++;
ptr2++;
len = ptr2 - ptr1 - 1;
if (len > (sizeof buf) - 1)
return;
memcpy(buf, ptr1, len);
buf[len] = '\0';
ll = strtonum(buf, 0, LONG_MAX, &errstr);
if (errstr != NULL)
return;
data->pid = ll;
ll = strtonum(ptr2, 0, UINT_MAX, &errstr);
if (errstr != NULL)
return;
data->idx = ll;
}
void

View File

@ -1,4 +1,4 @@
/* $Id: cmd-respawn-window.c,v 1.13 2009-01-23 16:59:14 nicm Exp $ */
/* $Id: cmd-respawn-window.c,v 1.14 2009-03-04 17:24:07 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -49,9 +49,8 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
struct window *w;
struct window_pane *wp;
struct session *s;
const char *env[] = CHILD_ENVIRON;
char buf[256], *cause;
u_int i;
const char **env;
char *cause;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
return (-1);
@ -67,10 +66,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
}
}
if (session_index(s, &i) != 0)
fatalx("session not found");
xsnprintf(buf, sizeof buf, "TMUX=%ld,%u", (long) getpid(), i);
env[0] = buf;
env = server_fill_environ(s);
wp = TAILQ_FIRST(&w->panes);
TAILQ_REMOVE(&w->panes, wp, entry);

View File

@ -1,4 +1,4 @@
/* $Id: cmd-split-window.c,v 1.8 2009-01-23 16:59:14 nicm Exp $ */
/* $Id: cmd-split-window.c,v 1.9 2009-03-04 17:24:07 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -139,18 +139,15 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
struct winlink *wl;
struct window *w;
struct window_pane *wp;
const char *env[] = CHILD_ENVIRON;
char buf[256], *cmd, *cwd, *cause;
u_int i, hlimit, lines;
const char **env;
char *cmd, *cwd, *cause;
u_int hlimit, lines;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
return (-1);
w = wl->window;
if (session_index(s, &i) != 0)
fatalx("session not found");
xsnprintf(buf, sizeof buf, "TMUX=%ld,%u", (long) getpid(), i);
env[0] = buf;
env = server_fill_environ(s);
cmd = data->cmd;
if (cmd == NULL)

View File

@ -1,4 +1,4 @@
/* $Id: server-fn.c,v 1.55 2009-02-27 16:01:31 nicm Exp $ */
/* $Id: server-fn.c,v 1.56 2009-03-04 17:24:07 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,6 +26,23 @@
int server_lock_callback(void *, const char *);
const char **
server_fill_environ(struct session *s)
{
static const char *env[] = { NULL /* TMUX= */, "TERM=screen", NULL };
static char *tmuxvar[MAXPATHLEN + 256];
u_int idx;
if (session_index(s, &idx) != 0)
fatalx("session not found");
xsnprintf(tmuxvar, sizeof tmuxvar,
"TMUX=%s,%ld,%u", socket_path, (long) getpid(), idx);
env[0] = tmuxvar;
return (env);
}
void
server_write_client(
struct client *c, enum hdrtype type, const void *buf, size_t len)

View File

@ -1,4 +1,4 @@
/* $Id: session.c,v 1.52 2009-01-23 16:59:14 nicm Exp $ */
/* $Id: session.c,v 1.53 2009-03-04 17:24:07 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -200,14 +200,10 @@ session_new(struct session *s,
const char *name, const char *cmd, const char *cwd, int idx, char **cause)
{
struct window *w;
const char *env[] = CHILD_ENVIRON;
char buf[256];
const char **env;
u_int i, hlimit;
if (session_index(s, &i) != 0)
fatalx("session not found");
xsnprintf(buf, sizeof buf, "TMUX=%ld,%u", (long) getpid(), i);
env[0] = buf;
env = server_fill_environ(s);
hlimit = options_get_number(&s->options, "history-limit");
w = window_create(name, cmd, cwd, env, s->sx, s->sy, hlimit, cause);

11
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.276 2009-03-02 18:05:40 nicm Exp $ */
/* $Id: tmux.h,v 1.277 2009-03-04 17:24:07 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -19,7 +19,7 @@
#ifndef TMUX_H
#define TMUX_H
#define PROTOCOL_VERSION -11
#define PROTOCOL_VERSION -12
/* Shut up gcc warnings about empty if bodies. */
#define RB_AUGMENT(x) do {} while (0)
@ -117,9 +117,6 @@ extern const char *__progname;
/* Default prompt history length. */
#define PROMPT_HISTORY 100
/* Default environment. */
#define CHILD_ENVIRON { NULL /* TMUX= */, "TERM=screen", NULL }
/* Minimum pane size. */
#define PANE_MINIMUM 4 /* includes separator line */
@ -1313,9 +1310,7 @@ int server_start(const char *);
int server_msg_dispatch(struct client *);
/* server-fn.c */
struct session *server_extract_session(
struct msg_command_data *, char *, char **);
void server_write(struct client *, enum hdrtype, const void *, size_t);
const char **server_fill_environ(struct session *);
void server_write_client(
struct client *, enum hdrtype, const void *, size_t);
void server_write_session(