From 81069f66f96dd83025fc6f2990619eb861199e10 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 13 Jul 2015 15:37:26 +0000 Subject: [PATCH 1/3] Add a format to show if client is a control client. From Bruno Sutic. --- format.c | 2 ++ tmux.1 | 1 + 2 files changed, 3 insertions(+) diff --git a/format.c b/format.c index 8a52b0e1..aff34abb 100644 --- a/format.c +++ b/format.c @@ -711,6 +711,8 @@ format_defaults_client(struct format_tree *ft, struct client *c) format_add(ft, "client_tty", "%s", c->tty.path); if (c->tty.termname != NULL) format_add(ft, "client_termname", "%s", c->tty.termname); + format_add(ft, "client_control_mode", "%d", + !!(c->flags & CLIENT_CONTROL)); t = c->creation_time.tv_sec; format_add(ft, "client_created", "%lld", (long long) t); diff --git a/tmux.1 b/tmux.1 index db5f314e..b4c608cb 100644 --- a/tmux.1 +++ b/tmux.1 @@ -3358,6 +3358,7 @@ The following variables are available, where appropriate: .It Li "client_activity_string" Ta "" Ta "String time client last had activity" .It Li "client_created" Ta "" Ta "Integer time client created" .It Li "client_created_string" Ta "" Ta "String time client created" +.It Li "client_control_mode" Ta "" Ta "1 if client is in control mode" .It Li "client_height" Ta "" Ta "Height of client" .It Li "client_last_session" Ta "" Ta "Name of the client's last session" .It Li "client_pid" Ta "" Ta "PID of client process" From c7374c31c4ba176e94825e8d734b5abe8a6879b1 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 13 Jul 2015 15:49:31 +0000 Subject: [PATCH 2/3] Initialize cwd fd to -1 so that we don't close fd 0 if the client is destroyed before it is changed. Also allow ttyname() to fail. Fixes problems when running out of file descriptors reported by Bruno Sutic. --- server-client.c | 5 +++-- tmux.h | 2 +- tty.c | 9 +++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/server-client.c b/server-client.c index 9beef4bc..4c03de91 100644 --- a/server-client.c +++ b/server-client.c @@ -96,6 +96,8 @@ server_client_create(int fd) environ_init(&c->environ); + c->cwd = -1; + c->cmdq = cmdq_new(c); c->cmdq->client_exit = 1; @@ -1253,12 +1255,11 @@ server_client_msg_identify(struct client *c, struct imsg *imsg) if (c->fd == -1) return; - if (!isatty(c->fd)) { + if (tty_init(&c->tty, c, c->fd, c->term) != 0) { close(c->fd); c->fd = -1; return; } - tty_init(&c->tty, c, c->fd, c->term); if (c->flags & CLIENT_UTF8) c->tty.flags |= TTY_UTF8; if (c->flags & CLIENT_256COLOURS) diff --git a/tmux.h b/tmux.h index 663832e5..e082aeab 100644 --- a/tmux.h +++ b/tmux.h @@ -1600,7 +1600,7 @@ void tty_putcode_ptr2(struct tty *, enum tty_code_code, const void *, void tty_puts(struct tty *, const char *); void tty_putc(struct tty *, u_char); void tty_putn(struct tty *, const void *, size_t, u_int); -void tty_init(struct tty *, struct client *, int, char *); +int tty_init(struct tty *, struct client *, int, char *); int tty_resize(struct tty *); int tty_set_size(struct tty *, u_int, u_int); void tty_set_class(struct tty *, u_int); diff --git a/tty.c b/tty.c index 63380c29..ffb36cb1 100644 --- a/tty.c +++ b/tty.c @@ -59,11 +59,14 @@ void tty_default_colours(struct grid_cell *, const struct window_pane *); #define tty_pane_full_width(tty, ctx) \ ((ctx)->xoff == 0 && screen_size_x((ctx)->wp->screen) >= (tty)->sx) -void +int tty_init(struct tty *tty, struct client *c, int fd, char *term) { char *path; + if (!isatty(fd)) + return (-1); + memset(tty, 0, sizeof *tty); tty->log_fd = -1; @@ -75,13 +78,15 @@ tty_init(struct tty *tty, struct client *c, int fd, char *term) tty->client = c; if ((path = ttyname(fd)) == NULL) - fatalx("ttyname failed"); + return (-1); tty->path = xstrdup(path); tty->cstyle = 0; tty->ccolour = xstrdup(""); tty->flags = 0; tty->term_flags = 0; + + return (0); } int From e45d624df288d914a1628d373ff245b03f7d600b Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 13 Jul 2015 15:51:31 +0000 Subject: [PATCH 3/3] Fix line endings. --- server-client.c | 6 +++--- tmux.h | 2 +- tty.c | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/server-client.c b/server-client.c index 4c03de91..09348b05 100644 --- a/server-client.c +++ b/server-client.c @@ -96,8 +96,8 @@ server_client_create(int fd) environ_init(&c->environ); - c->cwd = -1; - + c->cwd = -1; + c->cmdq = cmdq_new(c); c->cmdq->client_exit = 1; @@ -1255,7 +1255,7 @@ server_client_msg_identify(struct client *c, struct imsg *imsg) if (c->fd == -1) return; - if (tty_init(&c->tty, c, c->fd, c->term) != 0) { + if (tty_init(&c->tty, c, c->fd, c->term) != 0) { close(c->fd); c->fd = -1; return; diff --git a/tmux.h b/tmux.h index e082aeab..3aceff9d 100644 --- a/tmux.h +++ b/tmux.h @@ -1600,7 +1600,7 @@ void tty_putcode_ptr2(struct tty *, enum tty_code_code, const void *, void tty_puts(struct tty *, const char *); void tty_putc(struct tty *, u_char); void tty_putn(struct tty *, const void *, size_t, u_int); -int tty_init(struct tty *, struct client *, int, char *); +int tty_init(struct tty *, struct client *, int, char *); int tty_resize(struct tty *); int tty_set_size(struct tty *, u_int, u_int); void tty_set_class(struct tty *, u_int); diff --git a/tty.c b/tty.c index ffb36cb1..374fb8c6 100644 --- a/tty.c +++ b/tty.c @@ -59,14 +59,14 @@ void tty_default_colours(struct grid_cell *, const struct window_pane *); #define tty_pane_full_width(tty, ctx) \ ((ctx)->xoff == 0 && screen_size_x((ctx)->wp->screen) >= (tty)->sx) -int +int tty_init(struct tty *tty, struct client *c, int fd, char *term) { char *path; - if (!isatty(fd)) - return (-1); - + if (!isatty(fd)) + return (-1); + memset(tty, 0, sizeof *tty); tty->log_fd = -1; @@ -78,15 +78,15 @@ tty_init(struct tty *tty, struct client *c, int fd, char *term) tty->client = c; if ((path = ttyname(fd)) == NULL) - return (-1); + return (-1); tty->path = xstrdup(path); tty->cstyle = 0; tty->ccolour = xstrdup(""); tty->flags = 0; tty->term_flags = 0; - - return (0); + + return (0); } int