From 4dded23cd3da6e3268f3e91e966db59c1f735c75 Mon Sep 17 00:00:00 2001 From: Simon Vrouwe Date: Tue, 23 Nov 2021 13:01:56 +0200 Subject: [PATCH] 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. --- common/hsm_encryption.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/hsm_encryption.c b/common/hsm_encryption.c index c52fa8d6c..7e5778854 100644 --- a/common/hsm_encryption.c +++ b/common/hsm_encryption.c @@ -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, ¤t_term) != 0) { + if (tcsetattr(fileno(stdin), TCSANOW, ¤t_term) != 0) { *reason = "Could not restore terminal options."; free(passwd); return NULL;