summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/ChangeLog4
-rw-r--r--util/ttyio.c25
2 files changed, 24 insertions, 5 deletions
diff --git a/util/ChangeLog b/util/ChangeLog
index ece073420..c249e8d67 100644
--- a/util/ChangeLog
+++ b/util/ChangeLog
@@ -1,3 +1,7 @@
+Sat Aug 8 18:35:00 1998 Werner Koch (wk@(none))
+
+ * ttyio.c (cleanup): New.
+
Mon Aug 3 17:06:00 1998 Werner Koch (wk@(none))
* secmem.c (MAP_ANON): Add a macro test
diff --git a/util/ttyio.c b/util/ttyio.c
index 99927d660..38143cba5 100644
--- a/util/ttyio.c
+++ b/util/ttyio.c
@@ -56,9 +56,22 @@ static FILE *ttyfp = NULL;
static int initialized;
static int last_prompt_len;
+#ifdef HAVE_TCGETATTR
+static struct termios termsave;
+static int restore_termios;
+#endif
-
-
+#ifdef HAVE_TCGETATTR
+static void
+cleanup(void)
+{
+ if( restore_termios ) {
+ restore_termios = 0; /* do it prios in case it is interrupted again */
+ if( tcsetattr(fileno(ttyfp), TCSAFLUSH, &termsave) )
+ log_error("tcsetattr() failed: %s\n", strerror(errno) );
+ }
+}
+#endif
static void
init_ttyfp()
@@ -95,6 +108,9 @@ init_ttyfp()
if( !ttyfp )
log_fatal("cannot open /dev/tty: %s\n", strerror(errno) );
#endif
+ #ifdef HAVE_TCGETATTR
+ atexit( cleanup );
+ #endif
initialized = 1;
}
@@ -199,9 +215,6 @@ do_get( const char *prompt, int hidden )
char *buf;
byte cbuf[1];
int c, n, i;
- #ifdef HAVE_TCGETATTR
- struct termios termsave;
- #endif
if( !initialized )
init_ttyfp();
@@ -252,6 +265,7 @@ do_get( const char *prompt, int hidden )
if( tcgetattr(fileno(ttyfp), &termsave) )
log_fatal("tcgetattr() failed: %s\n", strerror(errno) );
+ restore_termios = 1;
term = termsave;
term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
if( tcsetattr( fileno(ttyfp), TCSAFLUSH, &term ) )
@@ -284,6 +298,7 @@ do_get( const char *prompt, int hidden )
#ifdef HAVE_TCGETATTR
if( tcsetattr(fileno(ttyfp), TCSAFLUSH, &termsave) )
log_error("tcsetattr() failed: %s\n", strerror(errno) );
+ restore_termios = 0;
#endif
}
#endif /* end unix version */