summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2013-01-19 21:22:29 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2013-01-19 21:22:29 +0000
commit48d0937f5c4ba4cac7aeb952b7845d1e9607753e (patch)
tree09a9f39c4331ad2f995e81a3b270bb0ef0aa5719
parent93672047394421a7c085b3ffcc047c299b846ac8 (diff)
Don't spin in ttgetc when stdin is lost (found by benno@).
While there prevent an unterminated recursion in panic(). ok lum@, benno@
-rw-r--r--usr.bin/mg/ttyio.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/usr.bin/mg/ttyio.c b/usr.bin/mg/ttyio.c
index 228a370c5a8..5ce855a0cc1 100644
--- a/usr.bin/mg/ttyio.c
+++ b/usr.bin/mg/ttyio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ttyio.c,v 1.32 2008/02/05 12:53:38 reyk Exp $ */
+/* $OpenBSD: ttyio.c,v 1.33 2013/01/19 21:22:28 florian Exp $ */
/* This file is in the public domain. */
@@ -173,7 +173,9 @@ ttgetc(void)
redraw(0, 0);
winch_flag = 0;
}
- } else if (ret == 1)
+ } else if (ret == -1 && errno == EIO)
+ panic("lost stdin");
+ else if (ret == 1)
break;
} while (1);
return ((int) c) & 0xFF;
@@ -196,6 +198,12 @@ charswaiting(void)
void
panic(char *s)
{
+ static int panicking = 0;
+
+ if (panicking)
+ return;
+ else
+ panicking = 1;
ttclose();
(void) fputs("panic: ", stderr);
(void) fputs(s, stderr);