1
0
Fork 0
forked from soccera/rdo

Don't search for tty, open it directly.

This commit is contained in:
sw1tchbl4d3 2022-12-20 22:51:14 +01:00
parent 2f0bdc7712
commit b34d64fd5c

View file

@ -6,8 +6,8 @@
char* readpassphrase(const char* prompt, char* buf, size_t bufsz, int read_pw_from_stdin) { char* readpassphrase(const char* prompt, char* buf, size_t bufsz, int read_pw_from_stdin) {
int n; int n;
int is_tty = !read_pw_from_stdin; int is_tty = !read_pw_from_stdin;
int infd = -1; int infd;
int outfd = -1; int outfd;
struct termios term; struct termios term;
@ -16,13 +16,9 @@ char* readpassphrase(const char* prompt, char* buf, size_t bufsz, int read_pw_fr
outfd = 1; outfd = 1;
is_tty = tcgetattr(outfd, &term) == 0; is_tty = tcgetattr(outfd, &term) == 0;
} else { } else {
for (int i = 0; i < 3; i++) { infd = outfd = open("/dev/tty", O_RDWR);
if (tcgetattr(i, &term) == 0) { if (!(infd >= 0 && tcgetattr(outfd, &term) == 0))
infd = i; return NULL;
outfd = i;
break;
}
}
} }
if (infd < 0) if (infd < 0)