hsmtool: use flag TCSANOW when disabling tty ECHO, fixes rare hang in test_hsm*

No idea why TCSAFLUSH was used, could not find anything in PR comments.
Also cannot explain exactly what causes the problem, but the hang can be reproduced
*with* TCSAFLUSH and not with TCSANOW.

According to termios doc:
TCSANOW
    the change occurs immediately.
TCSAFLUSH
    the change occurs after all output written to the object referred by fd has been
    transmitted, and all input that has been received but not read will be discarded
    before the change is made.
This commit is contained in:
Simon Vrouwe 2021-11-23 13:01:56 +02:00 committed by Rusty Russell
parent ae4623c21a
commit 4dded23cd3

View File

@ -103,7 +103,7 @@ char *read_stdin_pass(char **reason)
}
temp_term = current_term;
temp_term.c_lflag &= ~ECHO;
if (tcsetattr(fileno(stdin), TCSAFLUSH, &temp_term) != 0) {
if (tcsetattr(fileno(stdin), TCSANOW, &temp_term) != 0) {
*reason = "Could not disable pass echoing.";
return NULL;
}
@ -114,7 +114,7 @@ char *read_stdin_pass(char **reason)
}
/* Restore the original terminal */
if (tcsetattr(fileno(stdin), TCSAFLUSH, &current_term) != 0) {
if (tcsetattr(fileno(stdin), TCSANOW, &current_term) != 0) {
*reason = "Could not restore terminal options.";
free(passwd);
return NULL;