Read prompts from a fresh /dev/tty to avoid tty corruption

Replace pre-opened _RECOVERY_TTY handling with direct reads from /dev/tty in misc/build.func and misc/error_handler.func. The change opens /dev/tty at prompt time (with stty sane) so the prompt reads aren't affected by tty state corruption from lxc-attach|tee, simplifies the read logic by using a local response variable with a timeout, and removes the pre-open/close bookkeeping for _RECOVERY_TTY.
This commit is contained in:
CanbiZ (MickLesk)
2026-03-02 10:25:19 +01:00
parent 3cfe86512d
commit 374c4492d9
2 changed files with 6 additions and 21 deletions

View File

@@ -286,15 +286,10 @@ error_handler() {
echo -en "${YW}Remove broken container ${CTID}? (Y/n) [auto-remove in 60s]: ${CL}"
fi
# Use the pre-opened tty fd if available (survives tty corruption from lxc-attach|tee)
# Reset terminal state and read directly from /dev/tty (fresh open = clean state)
stty sane 2>/dev/null || true
local _read_fd="${_RECOVERY_TTY:-}"
local _read_src="</dev/tty"
if [[ -n "$_read_fd" ]] && { true <&"$_read_fd"; } 2>/dev/null; then
_read_src="<&$_read_fd"
fi
if eval "read -t 60 -r response $_read_src"; then
local response=""
if read -t 60 -r response </dev/tty 2>/dev/null; then
if [[ -z "$response" || "$response" =~ ^[Yy]$ ]]; then
echo ""
if declare -f msg_info >/dev/null 2>&1; then