Sync OpenBSD patchset 246:

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.
pull/1/head
Tiago Cunha 2009-08-14 21:23:20 +00:00
parent 0714e41148
commit e2a18894b3
5 changed files with 36 additions and 20 deletions

View File

@ -1,4 +1,4 @@
/* $Id: client.c,v 1.62 2009-08-14 21:04:04 tcunha Exp $ */
/* $Id: client.c,v 1.63 2009-08-14 21:23:20 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -123,7 +123,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);

View File

@ -1,4 +1,4 @@
/* $Id: server-msg.c,v 1.79 2009-08-14 21:17:54 tcunha Exp $ */
/* $Id: server-msg.c,v 1.80 2009-08-14 21:23:20 tcunha 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)

4
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.413 2009-08-14 21:20:01 tcunha Exp $ */
/* $Id: tmux.h,v 1.414 2009-08-14 21:23:20 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -1156,7 +1156,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 *);

16
tty.c
View File

@ -1,4 +1,4 @@
/* $Id: tty.c,v 1.124 2009-08-14 21:20:01 tcunha Exp $ */
/* $Id: tty.c,v 1.125 2009-08-14 21:23:20 tcunha 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)

View File

@ -1,4 +1,4 @@
/* $Id: window.c,v 1.100 2009-08-09 17:48:55 tcunha Exp $ */
/* $Id: window.c,v 1.101 2009-08-14 21:23:20 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -59,18 +59,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