Skip to content

Commit

Permalink
main: Restore tty state if password prompt is aborted
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cernekee committed Aug 2, 2014
1 parent b61bbfb commit e76aeca
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions main.c
Expand Up @@ -593,17 +593,19 @@ 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;
tcsetattr(fd, TCSANOW, &t);
fprintf(stderr, "\n");
}

if (!buf) {
perror(_("fgets (stdin)"));
exit(1);
}

c = strchr(buf, '\n');
if (c)
*c = 0;
Expand Down

0 comments on commit e76aeca

Please sign in to comment.