summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorVincent Labrecque <vincent@cvs.openbsd.org>2003-11-09 00:23:02 +0000
committerVincent Labrecque <vincent@cvs.openbsd.org>2003-11-09 00:23:02 +0000
commit84e85ae9e0d3c795f53a5f7c4a9b1c0f96a55d8e (patch)
tree71525f1dc4a46716efd057936d3a01ea2329b6be /usr.bin
parent3ef772dda034a88d9fc25bab029dbf0a18916b17 (diff)
fix up terminal correctly on panic (keeps terminal state correct when
started with an invalid $TERM) spotted by deraadt
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mg/ttyio.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/usr.bin/mg/ttyio.c b/usr.bin/mg/ttyio.c
index 0353007022e..c569f5863ff 100644
--- a/usr.bin/mg/ttyio.c
+++ b/usr.bin/mg/ttyio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ttyio.c,v 1.23 2002/09/15 14:08:57 vincent Exp $ */
+/* $OpenBSD: ttyio.c,v 1.24 2003/11/09 00:23:01 vincent Exp $ */
/*
* POSIX terminal I/O.
@@ -22,6 +22,7 @@
#define TCSASOFT 0
#endif
+int ttstarted;
char obuf[NOBUF]; /* Output buffer. */
int nobuf; /* Buffer count. */
struct termios oldtty; /* POSIX tty settings. */
@@ -37,7 +38,6 @@ int ncol; /* Terminal size, columns. */
void
ttopen(void)
{
-
if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO))
panic("standard input and output must be a terminal");
@@ -55,7 +55,6 @@ ttopen(void)
int
ttraw(void)
{
-
if (tcgetattr(0, &oldtty) < 0) {
ewprintf("ttopen can't get terminal attributes");
return (FALSE);
@@ -82,6 +81,8 @@ ttraw(void)
ewprintf("ttopen can't tcsetattr");
return (FALSE);
}
+ ttstarted = 1;
+
return (TRUE);
}
@@ -94,8 +95,11 @@ ttraw(void)
void
ttclose(void)
{
- if (ttcooked() == FALSE)
- panic(""); /* ttcooked() already printf'd */
+ if (ttstarted) {
+ if (ttcooked() == FALSE)
+ panic(""); /* ttcooked() already printf'd */
+ ttstarted = 0;
+ }
}
/*
@@ -187,6 +191,7 @@ typeahead(void)
void
panic(char *s)
{
+ ttclose();
(void) fputs("panic: ", stderr);
(void) fputs(s, stderr);
(void) fputc('\n', stderr);