diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-08-11 21:28:12 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-08-11 21:28:12 +0000 |
commit | e997d8c0270e98dc081ec35fd3b27a142181bb35 (patch) | |
tree | 5f051609240ad5d1e07addc2b7448b7a6cc95d49 /usr.bin | |
parent | 23dbb4e2c8eb65db51f5c4d1a8030edf6c5f52c1 (diff) |
Have the client pass its stdin fd to the server when identifying itself and
have the server use that rather than reopening the tty. If the fd isn't given,
use the old behaviour (so no need for a version change).
This allows tmux to be used as the shell, so also change so that when working
out the command to execute if default-command is empty (the default), tmux will
try not execute itself.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/client.c | 5 | ||||
-rw-r--r-- | usr.bin/tmux/server-msg.c | 10 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 4 | ||||
-rw-r--r-- | usr.bin/tmux/tty.c | 16 | ||||
-rw-r--r-- | usr.bin/tmux/window.c | 21 |
5 files changed, 36 insertions, 20 deletions
diff --git a/usr.bin/tmux/client.c b/usr.bin/tmux/client.c index e2606684090..669783624c5 100644 --- a/usr.bin/tmux/client.c +++ b/usr.bin/tmux/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.12 2009/08/11 17:18:35 nicm Exp $ */ +/* $OpenBSD: client.c,v 1.13 2009/08/11 21:28:11 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -119,7 +119,8 @@ server_started: if (strlcpy(data.tty, name, sizeof data.tty) >= sizeof data.tty) fatalx("ttyname failed"); - client_write_server(cctx, MSG_IDENTIFY, &data, sizeof data); + imsg_compose(&cctx->ibuf, MSG_IDENTIFY, + PROTOCOL_VERSION, -1, STDIN_FILENO, &data, sizeof data); } return (0); diff --git a/usr.bin/tmux/server-msg.c b/usr.bin/tmux/server-msg.c index 5c6a451d01c..23e51c8bebb 100644 --- a/usr.bin/tmux/server-msg.c +++ b/usr.bin/tmux/server-msg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-msg.c,v 1.12 2009/08/11 19:32:25 nicm Exp $ */ +/* $OpenBSD: server-msg.c,v 1.13 2009/08/11 21:28:11 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -27,7 +27,7 @@ #include "tmux.h" void server_msg_command(struct client *, struct msg_command_data *); -void server_msg_identify(struct client *, struct msg_identify_data *); +void server_msg_identify(struct client *, struct msg_identify_data *, int); void server_msg_resize(struct client *, struct msg_resize_data *); void printflike2 server_msg_command_error(struct cmd_ctx *, const char *, ...); @@ -76,7 +76,7 @@ server_msg_dispatch(struct client *c) fatalx("bad MSG_IDENTIFY size"); memcpy(&identifydata, imsg.data, sizeof identifydata); - server_msg_identify(c, &identifydata); + server_msg_identify(c, &identifydata, imsg.fd); break; case MSG_RESIZE: if (datalen != sizeof resizedata) @@ -235,7 +235,7 @@ error: } void -server_msg_identify(struct client *c, struct msg_identify_data *data) +server_msg_identify(struct client *c, struct msg_identify_data *data, int fd) { c->tty.sx = data->sx; c->tty.sy = data->sy; @@ -247,7 +247,7 @@ server_msg_identify(struct client *c, struct msg_identify_data *data) data->tty[(sizeof data->tty) - 1] = '\0'; data->term[(sizeof data->term) - 1] = '\0'; - tty_init(&c->tty, data->tty, data->term); + tty_init(&c->tty, fd, data->tty, data->term); if (data->flags & IDENTIFY_UTF8) c->tty.flags |= TTY_UTF8; if (data->flags & IDENTIFY_256COLOURS) diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index f7b23dfa4bb..78df2f196f7 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.77 2009/08/11 20:29:04 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.78 2009/08/11 21:28:11 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -1158,7 +1158,7 @@ void tty_putcode2(struct tty *, enum tty_code_code, int, int); void tty_puts(struct tty *, const char *); void tty_putc(struct tty *, u_char); void tty_pututf8(struct tty *, const struct grid_utf8 *); -void tty_init(struct tty *, char *, char *); +void tty_init(struct tty *, int, char *, char *); void tty_start_tty(struct tty *); void tty_stop_tty(struct tty *); void tty_detect_utf8(struct tty *); diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c index 03084c4a1ef..0c9bbe40604 100644 --- a/usr.bin/tmux/tty.c +++ b/usr.bin/tmux/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.21 2009/08/11 20:29:05 nicm Exp $ */ +/* $OpenBSD: tty.c,v 1.22 2009/08/11 21:28:11 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -45,9 +45,11 @@ void tty_cell(struct tty *, const struct grid_cell *, const struct grid_utf8 *); void -tty_init(struct tty *tty, char *path, char *term) +tty_init(struct tty *tty, int fd, char *path, char *term) { tty->path = xstrdup(path); + tty->fd = fd; + if (term == NULL || *term == '\0') tty->termname = xstrdup("unknown"); else @@ -59,12 +61,14 @@ tty_init(struct tty *tty, char *path, char *term) int tty_open(struct tty *tty, const char *overrides, char **cause) { - int mode; + int mode; - tty->fd = open(tty->path, O_RDWR|O_NONBLOCK); if (tty->fd == -1) { - xasprintf(cause, "%s: %s", tty->path, strerror(errno)); - return (-1); + tty->fd = open(tty->path, O_RDWR|O_NONBLOCK); + if (tty->fd == -1) { + xasprintf(cause, "%s: %s", tty->path, strerror(errno)); + return (-1); + } } if ((mode = fcntl(tty->fd, F_GETFL)) == -1) diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index 6fc13cec4db..11ff9ec610c 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.18 2009/08/08 21:52:43 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.19 2009/08/11 21:28:11 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -61,18 +61,29 @@ RB_GENERATE(winlinks, winlink, entry, winlink_cmp); const char * window_default_command(void) { - const char *shell; + const char *shell, *ptr; struct passwd *pw; shell = getenv("SHELL"); if (shell != NULL && *shell != '\0') - return (shell); + goto found; pw = getpwuid(getuid()); - if (pw != NULL && pw->pw_shell != NULL && *pw->pw_shell != '\0') - return (pw->pw_shell); + if (pw != NULL && pw->pw_shell != NULL && *pw->pw_shell != '\0') { + shell = pw->pw_shell; + goto found; + } return (_PATH_BSHELL); + +found: + if ((ptr = strrchr(shell, '/')) != NULL) + ptr++; + else + ptr = shell; + if (strcmp(ptr, __progname) == 0) + return (_PATH_BSHELL); + return (shell); } int |