aboutsummaryrefslogtreecommitdiff
path: root/tty.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2009-09-23 15:18:56 +0000
committerTiago Cunha <tcunha@gmx.com>2009-09-23 15:18:56 +0000
commit5be3fb86b9225842515f79a611a44d587814bd4c (patch)
tree88f4ef4bc24ee53dad55e025a7aaddbf335aa813 /tty.c
parent4dd332c95e0c439ae9532ffa391cd13eb769af01 (diff)
downloadrtmux-5be3fb86b9225842515f79a611a44d587814bd4c.tar.gz
rtmux-5be3fb86b9225842515f79a611a44d587814bd4c.tar.bz2
rtmux-5be3fb86b9225842515f79a611a44d587814bd4c.zip
Sync OpenBSD patchset 350:
Support -c like sh(1) to execute a command, useful when tmux is a login shell. Suggested by halex@. This includes another protocol version increase (the last for now) so again restart the tmux server before upgrading.
Diffstat (limited to 'tty.c')
-rw-r--r--tty.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/tty.c b/tty.c
index 1b0c3b7e..27a5fbe2 100644
--- a/tty.c
+++ b/tty.c
@@ -1,4 +1,4 @@
-/* $Id: tty.c,v 1.137 2009-09-23 15:08:21 tcunha Exp $ */
+/* $Id: tty.c,v 1.138 2009-09-23 15:18:56 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -44,7 +44,6 @@ void tty_cell(struct tty *,
void
tty_init(struct tty *tty, int fd, char *term)
{
- int mode;
char *path;
memset(tty, 0, sizeof *tty);
@@ -55,10 +54,6 @@ tty_init(struct tty *tty, int fd, char *term)
else
tty->termname = xstrdup(term);
- if ((mode = fcntl(fd, F_GETFL)) == -1)
- fatal("fcntl failed");
- if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1)
- fatal("fcntl failed");
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
fatal("fcntl failed");
tty->fd = fd;
@@ -129,6 +124,7 @@ void
tty_start_tty(struct tty *tty)
{
struct termios tio;
+ int mode;
#ifdef TIOCFLUSH
int what;
#endif
@@ -136,6 +132,11 @@ tty_start_tty(struct tty *tty)
if (tty->fd == -1)
return;
+ if ((mode = fcntl(tty->fd, F_GETFL)) == -1)
+ fatal("fcntl failed");
+ if (fcntl(tty->fd, F_SETFL, mode|O_NONBLOCK) == -1)
+ fatal("fcntl failed");
+
#if 0
tty_detect_utf8(tty);
#endif
@@ -187,6 +188,7 @@ void
tty_stop_tty(struct tty *tty)
{
struct winsize ws;
+ int mode;
if (!(tty->flags & TTY_STARTED))
return;
@@ -197,6 +199,10 @@ tty_stop_tty(struct tty *tty)
* because the fd is invalid. Things like ssh -t can easily leave us
* with a dead tty.
*/
+ if ((mode = fcntl(tty->fd, F_GETFL)) == -1)
+ return;
+ if (fcntl(tty->fd, F_SETFL, mode & ~O_NONBLOCK) == -1)
+ return;
if (ioctl(tty->fd, TIOCGWINSZ, &ws) == -1)
return;
if (tcsetattr(tty->fd, TCSANOW, &tty->tio) == -1)