Skip to content

Commit fa3c24f

Browse files
committed
initrd: fix TOTP loop by flushing input before ESC wait
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
1 parent 97466bd commit fa3c24f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

initrd/etc/functions

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,14 @@ show_totp_until_esc() {
16471647
local last_totp_time=0 last_totp=""
16481648
printf "\n" # reserve a line for updates
16491649

1650+
# Clear any pending keystrokes before we start displaying the TOTP.
1651+
# In particular, a stray Escape key from the previous passphrase
1652+
# prompt could be sitting in the input buffer and would cause the
1653+
# function to immediately return on the next iteration, confusing
1654+
# the user when they try to hit Esc again. Drain stdin until it's
1655+
# empty.
1656+
while IFS= read -r -t 0 -n 1 junk; do :; done
1657+
16501658
# Poll frequently (200ms) for responsiveness, but only refresh the
16511659
# displayed timestamp/TOTP when the displayed second changes. Cache
16521660
# the TOTP for a short interval to avoid repeated unseal calls.

0 commit comments

Comments
 (0)