hsm: Stabilize the hsm encryption and decryption tests

We were using sleeps to hope we catch the password prompt. This makes the test
flaky. So I added a help text followed by a `fflush` to make sure we catcht he
right moment, instead of guessing. The `fflush` is also useful for debugging
if a user ever pipes the output to a file it'd get buffered and the user would
wait forever. The same applies for automated systems such as `expect` or
`pexpect` based scripts that enter the password on prompt.
This commit is contained in:
Christian Decker
2019-11-25 17:15:39 +01:00
parent 9e59740268
commit c84473f82c
2 changed files with 29 additions and 24 deletions

View File

@@ -331,7 +331,12 @@ static char *opt_set_hsm_password(struct lightningd *ld)
temp_term.c_lflag &= ~ECHO;
if (tcsetattr(fileno(stdin), TCSAFLUSH, &temp_term) != 0)
return "Could not disable password echoing.";
printf("Enter hsm_secret password : ");
printf("The hsm_secret is encrypted with a password. In order to "
"decrypt it and start the node you must provide the password.\n");
printf("Enter hsm_secret password: ");
/* If we don't flush we might end up being buffered and we might seem
* to hang while we wait for the password. */
fflush(stdout);
if (getline(&passwd, &passwd_size, stdin) < 0)
return "Could not read password from stdin.";
if(passwd[strlen(passwd) - 1] == '\n')