-/* $OpenBSD: cmd-choose-client.c,v 1.31 2016/10/16 19:04:05 nicm Exp $ */
+/* $OpenBSD: cmd-choose-client.c,v 1.32 2017/04/05 10:49:46 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
*/
#define CHOOSE_CLIENT_TEMPLATE \
- "#{client_tty}: #{session_name} " \
+ "#{client_name}: #{session_name} " \
"[#{client_width}x#{client_height} #{client_termname}]" \
"#{?client_utf8, (utf8),}#{?client_readonly, (ro),} " \
"(last used #{t:client_activity})"
cur = idx = 0;
TAILQ_FOREACH(c1, &clients, entry) {
- if (c1->session == NULL || c1->tty.path == NULL)
+ if (c1->session == NULL)
continue;
if (c1 == item->client)
cur = idx;
format_add(cdata->ft, "line", "%u", idx);
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);
-/* $OpenBSD: cmd-find.c,v 1.42 2017/03/13 10:53:32 nicm Exp $ */
+/* $OpenBSD: cmd-find.c,v 1.43 2017/04/05 10:49:46 nicm Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicholas.marriott@gmail.com>
* sessions to those containing that pane (we still use the current
* 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) {
- if (strcmp(wp->tty, fs->item->client->tty.path) == 0)
+ if (strcmp(wp->tty, fs->item->client->ttyname) == 0)
break;
}
} else
struct client *c;
char *copy;
size_t size;
- const char *path;
/* A NULL argument means the current client. */
if (item != NULL && target == NULL) {
if (size != 0 && copy[size - 1] == ':')
copy[size - 1] = '\0';
- /* Check path of each client. */
+ /* Check name and path of each client. */
TAILQ_FOREACH(c, &clients, entry) {
- if (c->session == NULL || c->tty.path == NULL)
+ if (c->session == NULL)
continue;
- path = c->tty.path;
-
- /* Try for exact match. */
- if (strcmp(copy, path) == 0)
+ if (strcmp(copy, c->name) == 0)
break;
- /* Try without leading /dev. */
- if (strncmp(path, _PATH_DEV, (sizeof _PATH_DEV) - 1) != 0)
+ if (*c->ttyname == '\0')
+ continue;
+ if (strcmp(copy, c->ttyname) == 0)
+ break;
+ if (strncmp(c->ttyname, _PATH_DEV, (sizeof _PATH_DEV) - 1) != 0)
continue;
- if (strcmp(copy, path + (sizeof _PATH_DEV) - 1) == 0)
+ if (strcmp(copy, c->ttyname + (sizeof _PATH_DEV) - 1) == 0)
break;
}
-/* $OpenBSD: cmd-list-clients.c,v 1.31 2017/02/03 11:57:27 nicm Exp $ */
+/* $OpenBSD: cmd-list-clients.c,v 1.32 2017/04/05 10:49:46 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
*/
#define LIST_CLIENTS_TEMPLATE \
- "#{client_tty}: #{session_name} " \
+ "#{client_name}: #{session_name} " \
"[#{client_width}x#{client_height} #{client_termname}]" \
"#{?client_utf8, (utf8),} #{?client_readonly, (ro),}"
-/* $OpenBSD: format.c,v 1.123 2017/03/08 13:36:12 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.124 2017/04/05 10:49:46 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
if (ft->s == NULL)
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_height", "%u", tty->sy);
format_add(ft, "client_width", "%u", tty->sx);
- if (tty->path != NULL)
- format_add(ft, "client_tty", "%s", tty->path);
+ format_add(ft, "client_tty", "%s", c->ttyname);
format_add(ft, "client_control_mode", "%d",
!!(c->flags & CLIENT_CONTROL));
-/* $OpenBSD: screen-redraw.c,v 1.44 2017/02/08 15:41:41 nicm Exp $ */
+/* $OpenBSD: screen-redraw.c,v 1.45 2017/04/05 10:49:46 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
if (status_at_line(c) == 0)
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);
for (i = 0; i < wp->sy; i++)
-/* $OpenBSD: server-client.c,v 1.215 2017/03/09 22:00:46 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.216 2017/04/05 10:49:46 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
struct environ_entry *envent;
struct window_pane *wp;
- if (c->tty.path == NULL)
- return (0);
-
envent = environ_find(c->environ, "TMUX");
if (envent == NULL || *envent->value == '\0')
return (0);
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 (0);
if (!TAILQ_EMPTY(&c->queue))
fatalx("queue not empty");
- if (c->references == 0)
+ if (c->references == 0) {
+ free((void *)c->name);
free(c);
+ }
}
/* Detach a client. */
const char *data, *home;
size_t datalen;
int flags;
+ char *name;
if (c->flags & CLIENT_IDENTIFIED)
fatalx("out-of-order identify message");
return;
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);
+
if (c->flags & CLIENT_CONTROL) {
c->stdin_callback = control_callback;
xvasprintf(&s, fmt, 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->msg_time = time(NULL);
-.\" $OpenBSD: tmux.1,v 1.539 2017/03/22 07:16:54 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.540 2017/04/05 10:49:46 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: March 22 2017 $
+.Dd $Mdocdate: April 5 2017 $
.Dt TMUX 1
.Os
.Sh NAME
These specify the client, session, window or pane which a command should affect.
.Pp
.Ar target-client
-should be the name of the
+should be the name of the client,
+typically the
.Xr pty 4
file to which the client is connected, for example either of
.Pa /dev/ttyp1
.It Li "client_height" Ta "" Ta "Height of client"
.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_name" Ta "" Ta "Name of client"
.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_readonly" Ta "" Ta "1 if client is readonly"
-/* $OpenBSD: tmux.h,v 1.733 2017/03/22 07:16:54 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.734 2017/04/05 10:49:46 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
struct tty {
struct client *client;
- char *path;
u_int sx;
u_int sy;
/* Client connection. */
struct client {
+ const char *name;
struct tmuxpeer *peer;
struct cmdq_list queue;
-/* $OpenBSD: tty.c,v 1.257 2017/04/05 10:45:20 nicm Exp $ */
+/* $OpenBSD: tty.c,v 1.258 2017/04/05 10:49:46 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
int
tty_init(struct tty *tty, struct client *c, int fd, char *term)
{
- char *path;
-
if (!isatty(fd))
return (-1);
tty->term_name = xstrdup("unknown");
else
tty->term_name = xstrdup(term);
+
tty->fd = fd;
tty->client = c;
- if ((path = ttyname(fd)) == NULL)
- return (-1);
- tty->path = xstrdup(path);
tty->cstyle = 0;
tty->ccolour = xstrdup("");
int
tty_resize(struct tty *tty)
{
- struct winsize ws;
- u_int sx, sy;
+ struct client *c = tty->client;
+ struct winsize ws;
+ u_int sx, sy;
if (ioctl(tty->fd, TIOCGWINSZ, &ws) != -1) {
sx = ws.ws_col;
sx = 80;
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))
return (0);
tty_invalidate(tty);
tty_read_callback(__unused int fd, __unused short events, void *data)
{
struct tty *tty = data;
+ struct client *c = tty->client;
size_t size = EVBUFFER_LENGTH(tty->in);
int nread;
nread = evbuffer_read(tty->in, tty->fd, -1);
if (nread == -1)
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))
;
tty_write_callback(__unused int fd, __unused short events, void *data)
{
struct tty *tty = data;
+ struct client *c = tty->client;
size_t size = EVBUFFER_LENGTH(tty->out);
int nwrite;
nwrite = evbuffer_write(tty->out, tty->fd);
if (nwrite == -1)
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)
event_add(&tty->event_out, NULL);
tty_close(tty);
free(tty->ccolour);
- free(tty->path);
free(tty->term_name);
}
static void
tty_add(struct tty *tty, const char *buf, size_t len)
{
+ struct client *c = tty->client;
+
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)
write(tty_log_fd, buf, len);