From 8079673ef5d0691f7ccd4268cfd8fd3d8de44471 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 23 Sep 2020 09:47:56 -0500 Subject: Have read_password() read from tty device, handle ctrl-c and ctrl-d. --- lib/password.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/password.c b/lib/password.c index ab240aed..3a39d9e6 100644 --- a/lib/password.c +++ b/lib/password.c @@ -51,7 +51,7 @@ int read_password(char *buf, int buflen, char *mesg) { struct termios oldtermio; struct sigaction sa, oldsa; - int i, ret = 1; + int i, tty = tty_fd(), ret = 1; // NOP signal handler to return from the read. Use sigaction() instead // of xsignal() because we want to restore the old handler afterwards. @@ -59,13 +59,12 @@ int read_password(char *buf, int buflen, char *mesg) sa.sa_handler = generic_signal; sigaction(SIGINT, &sa, &oldsa); - tcflush(0, TCIFLUSH); - xset_terminal(0, 1, 0, &oldtermio); + tcflush(tty, TCIFLUSH); + xset_terminal(tty, 1, 0, &oldtermio); + dprintf(tty, "%s", mesg); - dprintf(1, "%s", mesg); - - for (i=0; i < buflen-1; i++) { - if ((ret = read(0, buf+i, 1)) < 0 || (!ret && !i)) { + for (i = 0; i