Merge branch 'obsd-master'

Conflicts:
	server-client.c
	tmux.1
This commit is contained in:
Thomas Adam
2017-04-06 11:10:17 +01:00
11 changed files with 78 additions and 57 deletions

2
cfg.c
View File

@ -27,7 +27,7 @@
#include "tmux.h" #include "tmux.h"
char *cfg_file; static char *cfg_file;
int cfg_finished; int cfg_finished;
static char **cfg_causes; static char **cfg_causes;
static u_int cfg_ncauses; static u_int cfg_ncauses;

View File

@ -28,7 +28,7 @@
*/ */
#define CHOOSE_CLIENT_TEMPLATE \ #define CHOOSE_CLIENT_TEMPLATE \
"#{client_tty}: #{session_name} " \ "#{client_name}: #{session_name} " \
"[#{client_width}x#{client_height} #{client_termname}]" \ "[#{client_width}x#{client_height} #{client_termname}]" \
"#{?client_utf8, (utf8),}#{?client_readonly, (ro),} " \ "#{?client_utf8, (utf8),}#{?client_readonly, (ro),} " \
"(last used #{t:client_activity})" "(last used #{t:client_activity})"
@ -85,7 +85,7 @@ cmd_choose_client_exec(struct cmd *self, struct cmdq_item *item)
cur = idx = 0; cur = idx = 0;
TAILQ_FOREACH(c1, &clients, entry) { TAILQ_FOREACH(c1, &clients, entry) {
if (c1->session == NULL || c1->tty.path == NULL) if (c1->session == NULL)
continue; continue;
if (c1 == item->client) if (c1 == item->client)
cur = idx; cur = idx;
@ -97,7 +97,7 @@ cmd_choose_client_exec(struct cmd *self, struct cmdq_item *item)
format_add(cdata->ft, "line", "%u", idx); format_add(cdata->ft, "line", "%u", idx);
format_defaults(cdata->ft, c1, NULL, NULL, NULL); format_defaults(cdata->ft, c1, NULL, NULL, NULL);
cdata->command = cmd_template_replace(action, c1->tty.path, 1); cdata->command = cmd_template_replace(action, c1->name, 1);
window_choose_add(wl->window->active, cdata); window_choose_add(wl->window->active, cdata);

View File

@ -42,10 +42,10 @@ static struct client *cmd_find_current_client(struct cmdq_item *);
static const char *cmd_find_map_table(const char *[][2], const char *); static const char *cmd_find_map_table(const char *[][2], const char *);
static int cmd_find_get_session(struct cmd_find_state *, const char *); static int cmd_find_get_session(struct cmd_find_state *, const char *);
static int cmd_find_get_window(struct cmd_find_state *, const char *); static int cmd_find_get_window(struct cmd_find_state *, const char *, int);
static int cmd_find_get_window_with_session(struct cmd_find_state *, static int cmd_find_get_window_with_session(struct cmd_find_state *,
const char *); const char *);
static int cmd_find_get_pane(struct cmd_find_state *, const char *); static int cmd_find_get_pane(struct cmd_find_state *, const char *, int);
static int cmd_find_get_pane_with_session(struct cmd_find_state *, static int cmd_find_get_pane_with_session(struct cmd_find_state *,
const char *); const char *);
static int cmd_find_get_pane_with_window(struct cmd_find_state *, static int cmd_find_get_pane_with_window(struct cmd_find_state *,
@ -255,9 +255,9 @@ cmd_find_current_session_with_client(struct cmd_find_state *fs)
* sessions to those containing that pane (we still use the current * sessions to those containing that pane (we still use the current
* window in the best session). * window in the best session).
*/ */
if (fs->item != NULL && fs->item->client->tty.path != NULL) { if (fs->item != NULL) {
RB_FOREACH(wp, window_pane_tree, &all_window_panes) { RB_FOREACH(wp, window_pane_tree, &all_window_panes) {
if (strcmp(wp->tty, fs->item->client->tty.path) == 0) if (strcmp(wp->tty, fs->item->client->ttyname) == 0)
break; break;
} }
} else } else
@ -463,7 +463,7 @@ cmd_find_get_session(struct cmd_find_state *fs, const char *session)
/* Find window from string. Fills in s, wl, w. */ /* Find window from string. Fills in s, wl, w. */
static int static int
cmd_find_get_window(struct cmd_find_state *fs, const char *window) cmd_find_get_window(struct cmd_find_state *fs, const char *window, int only)
{ {
log_debug("%s: %s", __func__, window); log_debug("%s: %s", __func__, window);
@ -483,7 +483,7 @@ cmd_find_get_window(struct cmd_find_state *fs, const char *window)
return (0); return (0);
/* Otherwise try as a session itself. */ /* Otherwise try as a session itself. */
if (cmd_find_get_session(fs, window) == 0) { if (!only && cmd_find_get_session(fs, window) == 0) {
fs->wl = fs->s->curw; fs->wl = fs->s->curw;
fs->w = fs->wl->window; fs->w = fs->wl->window;
if (~fs->flags & CMD_FIND_WINDOW_INDEX) if (~fs->flags & CMD_FIND_WINDOW_INDEX)
@ -650,7 +650,7 @@ cmd_find_get_window_with_session(struct cmd_find_state *fs, const char *window)
/* Find pane from string. Fills in s, wl, w, wp. */ /* Find pane from string. Fills in s, wl, w, wp. */
static int static int
cmd_find_get_pane(struct cmd_find_state *fs, const char *pane) cmd_find_get_pane(struct cmd_find_state *fs, const char *pane, int only)
{ {
log_debug("%s: %s", __func__, pane); log_debug("%s: %s", __func__, pane);
@ -674,7 +674,7 @@ cmd_find_get_pane(struct cmd_find_state *fs, const char *pane)
return (0); return (0);
/* Otherwise try as a window itself (this will also try as session). */ /* Otherwise try as a window itself (this will also try as session). */
if (cmd_find_get_window(fs, pane) == 0) { if (!only && cmd_find_get_window(fs, pane, 0) == 0) {
fs->wp = fs->w->active; fs->wp = fs->w->active;
return (0); return (0);
} }
@ -981,6 +981,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
struct mouse_event *m; struct mouse_event *m;
char *colon, *period, *copy = NULL; char *colon, *period, *copy = NULL;
const char *session, *window, *pane; const char *session, *window, *pane;
int window_only = 0, pane_only = 0;
/* Log the arguments. */ /* Log the arguments. */
if (target == NULL) if (target == NULL)
@ -1065,13 +1066,17 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
if (colon != NULL && period != NULL) { if (colon != NULL && period != NULL) {
session = copy; session = copy;
window = colon; window = colon;
window_only = 1;
pane = period; pane = period;
pane_only = 1;
} else if (colon != NULL && period == NULL) { } else if (colon != NULL && period == NULL) {
session = copy; session = copy;
window = colon; window = colon;
window_only = 1;
} else if (colon == NULL && period != NULL) { } else if (colon == NULL && period != NULL) {
window = copy; window = copy;
pane = period; pane = period;
pane_only = 1;
} else { } else {
if (*copy == '$') if (*copy == '$')
session = copy; session = copy;
@ -1178,7 +1183,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
/* No session. If window and pane, try them. */ /* No session. If window and pane, try them. */
if (window != NULL && pane != NULL) { if (window != NULL && pane != NULL) {
/* This will fill in session, winlink and window. */ /* This will fill in session, winlink and window. */
if (cmd_find_get_window(fs, window) != 0) if (cmd_find_get_window(fs, window, window_only) != 0)
goto no_window; goto no_window;
/* This will fill in pane. */ /* This will fill in pane. */
if (cmd_find_get_pane_with_window(fs, pane) != 0) if (cmd_find_get_pane_with_window(fs, pane) != 0)
@ -1189,7 +1194,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
/* If just window is present, try it. */ /* If just window is present, try it. */
if (window != NULL && pane == NULL) { if (window != NULL && pane == NULL) {
/* This will fill in session, winlink and window. */ /* This will fill in session, winlink and window. */
if (cmd_find_get_window(fs, window) != 0) if (cmd_find_get_window(fs, window, window_only) != 0)
goto no_window; goto no_window;
fs->wp = fs->wl->window->active; fs->wp = fs->wl->window->active;
goto found; goto found;
@ -1198,7 +1203,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
/* If just pane is present, try it. */ /* If just pane is present, try it. */
if (window == NULL && pane != NULL) { if (window == NULL && pane != NULL) {
/* This will fill in session, winlink, window and pane. */ /* This will fill in session, winlink, window and pane. */
if (cmd_find_get_pane(fs, pane) != 0) if (cmd_find_get_pane(fs, pane, pane_only) != 0)
goto no_pane; goto no_pane;
goto found; goto found;
} }
@ -1247,7 +1252,6 @@ cmd_find_client(struct cmdq_item *item, const char *target, int quiet)
struct client *c; struct client *c;
char *copy; char *copy;
size_t size; size_t size;
const char *path;
/* A NULL argument means the current client. */ /* A NULL argument means the current client. */
if (item != NULL && target == NULL) { if (item != NULL && target == NULL) {
@ -1264,20 +1268,20 @@ cmd_find_client(struct cmdq_item *item, const char *target, int quiet)
if (size != 0 && copy[size - 1] == ':') if (size != 0 && copy[size - 1] == ':')
copy[size - 1] = '\0'; copy[size - 1] = '\0';
/* Check path of each client. */ /* Check name and path of each client. */
TAILQ_FOREACH(c, &clients, entry) { TAILQ_FOREACH(c, &clients, entry) {
if (c->session == NULL || c->tty.path == NULL) if (c->session == NULL)
continue; continue;
path = c->tty.path; if (strcmp(copy, c->name) == 0)
/* Try for exact match. */
if (strcmp(copy, path) == 0)
break; break;
/* Try without leading /dev. */ if (*c->ttyname == '\0')
if (strncmp(path, _PATH_DEV, (sizeof _PATH_DEV) - 1) != 0)
continue; continue;
if (strcmp(copy, path + (sizeof _PATH_DEV) - 1) == 0) if (strcmp(copy, c->ttyname) == 0)
break;
if (strncmp(c->ttyname, _PATH_DEV, (sizeof _PATH_DEV) - 1) != 0)
continue;
if (strcmp(copy, c->ttyname + (sizeof _PATH_DEV) - 1) == 0)
break; break;
} }

View File

@ -29,7 +29,7 @@
*/ */
#define LIST_CLIENTS_TEMPLATE \ #define LIST_CLIENTS_TEMPLATE \
"#{client_tty}: #{session_name} " \ "#{client_name}: #{session_name} " \
"[#{client_width}x#{client_height} #{client_termname}]" \ "[#{client_width}x#{client_height} #{client_termname}]" \
"#{?client_utf8, (utf8),} #{?client_readonly, (ro),}" "#{?client_utf8, (utf8),} #{?client_readonly, (ro),}"

View File

@ -1159,11 +1159,11 @@ format_defaults_client(struct format_tree *ft, struct client *c)
if (ft->s == NULL) if (ft->s == NULL)
ft->s = c->session; ft->s = c->session;
format_add(ft, "client_name", "%s", c->name);
format_add(ft, "client_pid", "%ld", (long) c->pid); format_add(ft, "client_pid", "%ld", (long) c->pid);
format_add(ft, "client_height", "%u", tty->sy); format_add(ft, "client_height", "%u", tty->sy);
format_add(ft, "client_width", "%u", tty->sx); format_add(ft, "client_width", "%u", tty->sx);
if (tty->path != NULL) format_add(ft, "client_tty", "%s", c->ttyname);
format_add(ft, "client_tty", "%s", tty->path);
format_add(ft, "client_control_mode", "%d", format_add(ft, "client_control_mode", "%d",
!!(c->flags & CLIENT_CONTROL)); !!(c->flags & CLIENT_CONTROL));

View File

@ -260,6 +260,8 @@ key_bindings_init(void)
"bind -Tcopy-mode n send -X search-again", "bind -Tcopy-mode n send -X search-again",
"bind -Tcopy-mode q send -X cancel", "bind -Tcopy-mode q send -X cancel",
"bind -Tcopy-mode t command-prompt -1p'jump to forward' 'send -X jump-to-forward \"%%%\"'", "bind -Tcopy-mode t command-prompt -1p'jump to forward' 'send -X jump-to-forward \"%%%\"'",
"bind -Tcopy-mode Home send -X start-of-line",
"bind -Tcopy-mode End send -X end-of-line",
"bind -Tcopy-mode MouseDown1Pane select-pane", "bind -Tcopy-mode MouseDown1Pane select-pane",
"bind -Tcopy-mode MouseDrag1Pane select-pane\\; send -X begin-selection", "bind -Tcopy-mode MouseDrag1Pane select-pane\\; send -X begin-selection",
"bind -Tcopy-mode MouseDragEnd1Pane send -X copy-selection-and-cancel", "bind -Tcopy-mode MouseDragEnd1Pane send -X copy-selection-and-cancel",

View File

@ -423,7 +423,7 @@ screen_redraw_pane(struct client *c, struct window_pane *wp)
if (status_at_line(c) == 0) if (status_at_line(c) == 0)
yoff++; yoff++;
log_debug("%s: redraw pane %%%u (at %u,%u)", c->tty.path, wp->id, log_debug("%s: redraw pane %%%u (at %u,%u)", c->name, wp->id,
wp->xoff, yoff); wp->xoff, yoff);
for (i = 0; i < wp->sy; i++) for (i = 0; i < wp->sy; i++)

View File

@ -97,15 +97,12 @@ server_client_check_nested(struct client *c)
struct environ_entry *envent; struct environ_entry *envent;
struct window_pane *wp; struct window_pane *wp;
if (c->tty.path == NULL)
return (0);
envent = environ_find(c->environ, "TMUX"); envent = environ_find(c->environ, "TMUX");
if (envent == NULL || *envent->value == '\0') if (envent == NULL || *envent->value == '\0')
return (0); return (0);
RB_FOREACH(wp, window_pane_tree, &all_window_panes) { RB_FOREACH(wp, window_pane_tree, &all_window_panes) {
if (strcmp(wp->tty, c->tty.path) == 0) if (strcmp(wp->tty, c->ttyname) == 0)
return (1); return (1);
} }
return (0); return (0);
@ -320,9 +317,11 @@ server_client_free(__unused int fd, __unused short events, void *arg)
if (!TAILQ_EMPTY(&c->queue)) if (!TAILQ_EMPTY(&c->queue))
fatalx("queue not empty"); fatalx("queue not empty");
if (c->references == 0) if (c->references == 0) {
free((void *)c->name);
free(c); free(c);
} }
}
/* Detach a client. */ /* Detach a client. */
void void
@ -1478,6 +1477,7 @@ server_client_dispatch_identify(struct client *c, struct imsg *imsg)
const char *data, *home; const char *data, *home;
size_t datalen; size_t datalen;
int flags; int flags;
char *name;
if (c->flags & CLIENT_IDENTIFIED) if (c->flags & CLIENT_IDENTIFIED)
fatalx("out-of-order identify message"); fatalx("out-of-order identify message");
@ -1543,6 +1543,13 @@ server_client_dispatch_identify(struct client *c, struct imsg *imsg)
return; return;
c->flags |= CLIENT_IDENTIFIED; c->flags |= CLIENT_IDENTIFIED;
if (*c->ttyname != '\0')
name = xstrdup(c->ttyname);
else
xasprintf(&name, "client-%ld", (long)c->pid);
c->name = name;
log_debug("client %p name is %s", c, c->name);
#ifdef __CYGWIN__ #ifdef __CYGWIN__
c->fd = open(c->ttyname, O_RDWR|O_NOCTTY); c->fd = open(c->ttyname, O_RDWR|O_NOCTTY);
#endif #endif
@ -1697,7 +1704,7 @@ server_client_add_message(struct client *c, const char *fmt, ...)
xvasprintf(&s, fmt, ap); xvasprintf(&s, fmt, ap);
va_end(ap); va_end(ap);
log_debug("%s: message %s", c->tty.path, s); log_debug("message %s (client %p)", s, c);
msg = xcalloc(1, sizeof *msg); msg = xcalloc(1, sizeof *msg);
msg->msg_time = time(NULL); msg->msg_time = time(NULL);

4
tmux.1
View File

@ -371,7 +371,8 @@ or
These specify the client, session, window or pane which a command should affect. These specify the client, session, window or pane which a command should affect.
.Pp .Pp
.Ar target-client .Ar target-client
is the name of the should be the name of the client,
typically the
.Xr pty 4 .Xr pty 4
file to which the client is connected, for example either of file to which the client is connected, for example either of
.Pa /dev/ttyp1 .Pa /dev/ttyp1
@ -3514,6 +3515,7 @@ The following variables are available, where appropriate:
.It Li "client_height" Ta "" Ta "Height of client" .It Li "client_height" Ta "" Ta "Height of client"
.It Li "client_key_table" Ta "" Ta "Current key table" .It Li "client_key_table" Ta "" Ta "Current key table"
.It Li "client_last_session" Ta "" Ta "Name of the client's last session" .It Li "client_last_session" Ta "" Ta "Name of the client's last session"
.It Li "client_name" Ta "" Ta "Name of client"
.It Li "client_pid" Ta "" Ta "PID of client process" .It Li "client_pid" Ta "" Ta "PID of client process"
.It Li "client_prefix" Ta "" Ta "1 if prefix key has been pressed" .It Li "client_prefix" Ta "" Ta "1 if prefix key has been pressed"
.It Li "client_readonly" Ta "" Ta "1 if client is readonly" .It Li "client_readonly" Ta "" Ta "1 if client is readonly"

2
tmux.h
View File

@ -1025,7 +1025,6 @@ LIST_HEAD(tty_terms, tty_term);
struct tty { struct tty {
struct client *client; struct client *client;
char *path;
u_int sx; u_int sx;
u_int sy; u_int sy;
@ -1289,6 +1288,7 @@ struct cmd_entry {
/* Client connection. */ /* Client connection. */
struct client { struct client {
const char *name;
struct tmuxpeer *peer; struct tmuxpeer *peer;
struct cmdq_list queue; struct cmdq_list queue;

42
tty.c
View File

@ -94,8 +94,6 @@ tty_create_log(void)
int int
tty_init(struct tty *tty, struct client *c, int fd, char *term) tty_init(struct tty *tty, struct client *c, int fd, char *term)
{ {
char *path;
if (!isatty(fd)) if (!isatty(fd))
return (-1); return (-1);
@ -105,12 +103,10 @@ tty_init(struct tty *tty, struct client *c, int fd, char *term)
tty->term_name = xstrdup("unknown"); tty->term_name = xstrdup("unknown");
else else
tty->term_name = xstrdup(term); tty->term_name = xstrdup(term);
tty->fd = fd; tty->fd = fd;
tty->client = c; tty->client = c;
if ((path = ttyname(fd)) == NULL)
return (-1);
tty->path = xstrdup(path);
tty->cstyle = 0; tty->cstyle = 0;
tty->ccolour = xstrdup(""); tty->ccolour = xstrdup("");
@ -125,6 +121,7 @@ tty_init(struct tty *tty, struct client *c, int fd, char *term)
int int
tty_resize(struct tty *tty) tty_resize(struct tty *tty)
{ {
struct client *c = tty->client;
struct winsize ws; struct winsize ws;
u_int sx, sy; u_int sx, sy;
@ -139,7 +136,8 @@ tty_resize(struct tty *tty)
sx = 80; sx = 80;
sy = 24; sy = 24;
} }
log_debug("%s: %s now %ux%u", __func__, tty->path, sx, sy); log_debug("%s: %s now %ux%u", __func__, c->name, sx, sy);
if (!tty_set_size(tty, sx, sy)) if (!tty_set_size(tty, sx, sy))
return (0); return (0);
tty_invalidate(tty); tty_invalidate(tty);
@ -160,13 +158,14 @@ static void
tty_read_callback(__unused int fd, __unused short events, void *data) tty_read_callback(__unused int fd, __unused short events, void *data)
{ {
struct tty *tty = data; struct tty *tty = data;
struct client *c = tty->client;
size_t size = EVBUFFER_LENGTH(tty->in); size_t size = EVBUFFER_LENGTH(tty->in);
int nread; int nread;
nread = evbuffer_read(tty->in, tty->fd, -1); nread = evbuffer_read(tty->in, tty->fd, -1);
if (nread == -1) if (nread == -1)
return; return;
log_debug("%s: read %d bytes (already %zu)", tty->path, nread, size); log_debug("%s: read %d bytes (already %zu)", c->name, nread, size);
while (tty_keys_next(tty)) while (tty_keys_next(tty))
; ;
@ -176,13 +175,14 @@ static void
tty_write_callback(__unused int fd, __unused short events, void *data) tty_write_callback(__unused int fd, __unused short events, void *data)
{ {
struct tty *tty = data; struct tty *tty = data;
struct client *c = tty->client;
size_t size = EVBUFFER_LENGTH(tty->out); size_t size = EVBUFFER_LENGTH(tty->out);
int nwrite; int nwrite;
nwrite = evbuffer_write(tty->out, tty->fd); nwrite = evbuffer_write(tty->out, tty->fd);
if (nwrite == -1) if (nwrite == -1)
return; return;
log_debug("%s: wrote %d bytes (of %zu)", tty->path, nwrite, size); log_debug("%s: wrote %d bytes (of %zu)", c->name, nwrite, size);
if (EVBUFFER_LENGTH(tty->out) != 0) if (EVBUFFER_LENGTH(tty->out) != 0)
event_add(&tty->event_out, NULL); event_add(&tty->event_out, NULL);
@ -351,7 +351,6 @@ tty_free(struct tty *tty)
tty_close(tty); tty_close(tty);
free(tty->ccolour); free(tty->ccolour);
free(tty->path);
free(tty->term_name); free(tty->term_name);
} }
@ -424,8 +423,10 @@ tty_putcode_ptr2(struct tty *tty, enum tty_code_code code, const void *a,
static void static void
tty_add(struct tty *tty, const char *buf, size_t len) tty_add(struct tty *tty, const char *buf, size_t len)
{ {
struct client *c = tty->client;
evbuffer_add(tty->out, buf, len); evbuffer_add(tty->out, buf, len);
log_debug("%s: %.*s", tty->path, (int)len, (const char *)buf); log_debug("%s: %.*s", c->name, (int)len, (const char *)buf);
if (tty_log_fd != -1) if (tty_log_fd != -1)
write(tty_log_fd, buf, len); write(tty_log_fd, buf, len);
@ -602,8 +603,17 @@ tty_emulate_repeat(struct tty *tty, enum tty_code_code code,
static void static void
tty_repeat_space(struct tty *tty, u_int n) tty_repeat_space(struct tty *tty, u_int n)
{ {
while (n-- > 0) static char s[500];
tty_putc(tty, ' ');
if (*s != ' ')
memset(s, ' ', sizeof s);
while (n > sizeof s) {
tty_putn(tty, s, sizeof s, sizeof s);
n -= sizeof s;
}
if (n != 0)
tty_putn(tty, s, n, n);
} }
/* /*
@ -856,8 +866,6 @@ tty_cmd_deletecharacter(struct tty *tty, const struct tty_ctx *ctx)
void void
tty_cmd_clearcharacter(struct tty *tty, const struct tty_ctx *ctx) tty_cmd_clearcharacter(struct tty *tty, const struct tty_ctx *ctx)
{ {
u_int i;
tty_attributes(tty, &grid_default_cell, ctx->wp); tty_attributes(tty, &grid_default_cell, ctx->wp);
tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
@ -865,10 +873,8 @@ tty_cmd_clearcharacter(struct tty *tty, const struct tty_ctx *ctx)
if (tty_term_has(tty->term, TTYC_ECH) && if (tty_term_has(tty->term, TTYC_ECH) &&
!tty_fake_bce(tty, ctx->wp, ctx->bg)) !tty_fake_bce(tty, ctx->wp, ctx->bg))
tty_putcode1(tty, TTYC_ECH, ctx->num); tty_putcode1(tty, TTYC_ECH, ctx->num);
else { else
for (i = 0; i < ctx->num; i++) tty_repeat_space(tty, ctx->num);
tty_putc(tty, ' ');
}
} }
void void