]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
main: Restore tty state if password prompt is aborted
authorKevin Cernekee <cernekee@gmail.com>
Sat, 2 Aug 2014 20:20:34 +0000 (13:20 -0700)
committerKevin Cernekee <cernekee@gmail.com>
Sat, 2 Aug 2014 22:51:21 +0000 (15:51 -0700)
On Linux, hitting ^C on any of the password prompts now leaves ECHO
disabled, so the user needs to run "stty sane".  Restore the correct
settings prior to exiting.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
main.c

diff --git a/main.c b/main.c
index 1f46bb743451397203b53b7528d71b9370575899..2908f9c1dff4c11928ddd2b6b47dd5e32db8ca0d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -593,10 +593,7 @@ static void read_stdin(char **string, int hidden)
                tcsetattr(fd, TCSANOW, &t);
        }
 
-       if (!fgets(buf, 1025, stdin)) {
-               perror(_("fgets (stdin)"));
-               exit(1);
-       }
+       buf = fgets(buf, 1025, stdin);
 
        if (hidden) {
                t.c_lflag |= ECHO;
@@ -604,6 +601,11 @@ static void read_stdin(char **string, int hidden)
                fprintf(stderr, "\n");
        }
 
+       if (!buf) {
+               perror(_("fgets (stdin)"));
+               exit(1);
+       }
+
        c = strchr(buf, '\n');
        if (c)
                *c = 0;