diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2008-01-02 19:22:21 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2008-01-02 19:22:21 +0000 |
commit | ccfeb316a674370778390dc3192045fbe18113fe (patch) | |
tree | 6604967151f3507e1236e021c61ea60c0db7aee1 /tty.c | |
parent | 34b7810afe016695b7445a5acfa796423734db56 (diff) |
Don't attempt to reset tty if it is dead.
Diffstat (limited to 'tty.c')
-rw-r--r-- | tty.c | 42 |
1 files changed, 25 insertions, 17 deletions
@@ -1,4 +1,4 @@ -/* $Id: tty.c,v 1.17 2007-12-16 17:18:43 nicm Exp $ */ +/* $Id: tty.c,v 1.18 2008-01-02 19:22:21 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -124,22 +124,28 @@ tty_close(struct tty *tty) if (tty->fd == -1) return; - if (ioctl(tty->fd, TIOCGWINSZ, &ws) == -1) - fatal("ioctl(TIOCGWINSZ)"); - if (tcsetattr(tty->fd, TCSANOW, &tty->tio) != 0) - fatal("tcsetattr failed"); - - if (change_scroll_region != NULL) - tty_raw(tty, tparm(change_scroll_region, 0, ws.ws_row - 1)); - if (keypad_local != NULL) - tty_raw(tty, keypad_local); - if (exit_ca_mode != NULL) - tty_raw(tty, exit_ca_mode); - tty_raw(tty, clear_screen); - if (cursor_normal != NULL) - tty_raw(tty, cursor_normal); - if (exit_attribute_mode != NULL) - tty_raw(tty, exit_attribute_mode); + /* + * Skip any writing if the fd is invalid. Things like ssh -t can + * easily leave us with a dead tty. + */ + if (ioctl(tty->fd, TIOCGWINSZ, &ws) == -1) { + if (errno != EBADF && errno != ENXIO) + fatal("ioctl(TIOCGWINSZ)"); + } else { + if (tcsetattr(tty->fd, TCSANOW, &tty->tio) != 0) + fatal("tcsetattr failed"); + + tty_raw(tty, tparm(change_scroll_region, 0, ws.ws_row - 1)); + if (keypad_local != NULL) + tty_raw(tty, keypad_local); + if (exit_ca_mode != NULL) + tty_raw(tty, exit_ca_mode); + tty_raw(tty, clear_screen); + if (cursor_normal != NULL) + tty_raw(tty, cursor_normal); + if (exit_attribute_mode != NULL) + tty_raw(tty, exit_attribute_mode); + } tty_free_term(tty->term); tty_keys_free(tty); @@ -336,6 +342,8 @@ tty_vwrite(struct tty *tty, unused struct screen *s, int cmd, va_list ap) char ch; u_int i, ua, ub; + if (tty->term == NULL) /* XXX XXX */ + return; set_curterm(tty->term->term); switch (cmd) { |