summaryrefslogtreecommitdiffstats
path: root/tty.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2007-12-06 20:53:48 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2007-12-06 20:53:48 +0000
commit83393d3c87b2b0706d1b3b442902a631cc078afa (patch)
tree1ff9f7005acdb28ddb4a35cb59867eb75c0504bc /tty.c
parent91d790411ffe98004b3691ce42ac61482e4685c6 (diff)
Only close the tty during exit process and leave freeing it to when the socket is lost.
Diffstat (limited to 'tty.c')
-rw-r--r--tty.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/tty.c b/tty.c
index 389d9d32..0d38b11e 100644
--- a/tty.c
+++ b/tty.c
@@ -1,4 +1,4 @@
-/* $Id: tty.c,v 1.12 2007-12-06 18:28:55 nicm Exp $ */
+/* $Id: tty.c,v 1.13 2007-12-06 20:53:48 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -49,7 +49,10 @@ void
tty_init(struct tty *tty, char *path, char *term)
{
tty->path = xstrdup(path);
- tty->termname = xstrdup(term);
+ if (term == NULL)
+ tty->termname = xstrdup("unknown");
+ else
+ tty->termname = xstrdup(term);
}
int
@@ -64,8 +67,6 @@ tty_open(struct tty *tty, char **cause)
return (-1);
}
- if (tty->termname == NULL)
- tty->termname = xstrdup("unknown");
if ((tty->term = tty_find_term(tty->termname, tty->fd, cause)) == NULL)
goto error;
@@ -118,6 +119,9 @@ tty_close(struct tty *tty)
{
struct winsize ws;
+ if (tty->fd == -1)
+ return;
+
if (ioctl(tty->fd, TIOCGWINSZ, &ws) == -1)
fatal("ioctl(TIOCGWINSZ)");
if (tcsetattr(tty->fd, TCSANOW, &tty->tio) != 0)
@@ -148,8 +152,7 @@ tty_close(struct tty *tty)
void
tty_free(struct tty *tty)
{
- if (tty->fd != -1)
- tty_close(tty);
+ tty_close(tty);
if (tty->path != NULL)
xfree(tty->path);