forked from soccera/rdo
Use the correct file descriptor for printing
Before we used printf("\n"); to simulate the enter key the user pressed, which prints to normal stdout, which could have been redirected. Now we directly write to the found TTY. We also close the TTY file descriptor on every code path now.
This commit is contained in:
parent
66d15caad4
commit
fd4ee6a712
1 changed files with 6 additions and 4 deletions
|
@ -39,23 +39,25 @@ char* readpassphrase(const char* prompt, char* buf, size_t bufsz) {
|
|||
|
||||
if (write(fd, prompt, strlen(prompt)) < 0) {
|
||||
tcsetattr(ttyfd, 0, &term);
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
n = read(fd, buf, bufsz);
|
||||
if (n < 0) {
|
||||
tcsetattr(ttyfd, 0, &term);
|
||||
printf("\n");
|
||||
n = write(fd, "\n", 1);
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buf[n-1] = '\0';
|
||||
|
||||
// NOTE: As we disabled echo, the enter sent by the user isn't displayed, so we resend it.
|
||||
n = write(fd, "\n", 1);
|
||||
|
||||
close(fd);
|
||||
tcsetattr(ttyfd, 0, &term);
|
||||
|
||||
// NOTE: As we disabled echo, the enter sent by the user isn't displayed.
|
||||
printf("\n");
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue