From 683edbff7abb7cf9bd3221458a1ff7066923329f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=98tefan=20Talpalaru?= Date: Tue, 16 Mar 2021 09:06:45 +0100 Subject: [PATCH] restore terminal echoing after pressing Ctrl+C at a password prompt (#2412) --- beacon_chain/nimbus_beacon_node.nim | 2 ++ beacon_chain/nimbus_binary_common.nim | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 32d5b8b1a..c00ec9321 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -1916,6 +1916,8 @@ programMain: when defined(windows): # workaround for https://github.com/nim-lang/Nim/issues/4057 setupForeignThreadGc() + # in case a password prompt disabled echoing + resetStdin() echo "" # If we interrupt during an interactive prompt, this # will move the cursor to the next line notice "Shutting down after having received SIGINT" diff --git a/beacon_chain/nimbus_binary_common.nim b/beacon_chain/nimbus_binary_common.nim index 492d50e44..164070aa6 100644 --- a/beacon_chain/nimbus_binary_common.nim +++ b/beacon_chain/nimbus_binary_common.nim @@ -20,6 +20,9 @@ import ./spec/[datatypes, crypto, helpers], beacon_clock, filepath, ./networking/eth2_network +when defined(posix): + import termios + proc setupStdoutLogging*(logLevel: string) = when compiles(defaultChroniclesStream.output.writer): defaultChroniclesStream.outputs[0].writer = @@ -107,3 +110,13 @@ proc checkIfShouldStopAtEpoch*(scheduledSlot: Slot, stopAtEpoch: uint64) = # Brute-force, but ensure it's reliable enough to run in CI. quit(0) + +proc resetStdin*() = + when defined(posix): + # restore echoing, in case it was disabled by a password prompt + let fd = stdin.getFileHandle() + var attrs: Termios + discard fd.tcGetAttr(attrs.addr) + attrs.c_lflag = attrs.c_lflag or Cflag(ECHO) + discard fd.tcSetAttr(TCSANOW, attrs.addr) +