From 91025e4970eb8083983639437b3e0fd18db93cfe Mon Sep 17 00:00:00 2001 From: Yellowcooln <12516003+yellowcooln@users.noreply.github.com> Date: Thu, 23 Apr 2026 16:09:09 -0400 Subject: [PATCH] Use raw tty for Buildroot password prompt --- buildroot-manage.sh | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/buildroot-manage.sh b/buildroot-manage.sh index 0524fad..733b5b9 100644 --- a/buildroot-manage.sh +++ b/buildroot-manage.sh @@ -102,41 +102,35 @@ import tty prompt = sys.argv[1] try: - tty_stream = open("/dev/tty", "r+", encoding="utf-8", newline="") + tty_fd = os.open("/dev/tty", os.O_RDWR) except OSError: print("Interactive admin password prompt requires a TTY. Set PYMC_ADMIN_PASSWORD instead.", file=sys.stderr) raise SystemExit(1) -fd = tty_stream.fileno() - def read_secret(label: str) -> str: - tty_stream.write(f"{label}: ") - tty_stream.flush() - original = termios.tcgetattr(fd) + os.write(tty_fd, f"{label}: ".encode()) + original = termios.tcgetattr(tty_fd) chars = [] try: - tty.setraw(fd) + tty.setraw(tty_fd) while True: - ch = tty_stream.read(1) - if ch in ("\r", "\n"): - tty_stream.write("\n") - tty_stream.flush() + ch = os.read(tty_fd, 1) + if ch in (b"\r", b"\n"): + os.write(tty_fd, b"\n") return "".join(chars) - if ch == "\x03": + if ch == b"\x03": raise KeyboardInterrupt - if ch in ("\x7f", "\b"): + if ch in (b"\x7f", b"\x08"): if chars: chars.pop() - tty_stream.write("\b \b") - tty_stream.flush() + os.write(tty_fd, b"\b \b") continue - if not ch or ord(ch) < 32: + if not ch or ch[0] < 32: continue - chars.append(ch) - tty_stream.write("*") - tty_stream.flush() + chars.append(ch.decode(errors="ignore")) + os.write(tty_fd, b"*") finally: - termios.tcsetattr(fd, termios.TCSADRAIN, original) + termios.tcsetattr(tty_fd, termios.TCSADRAIN, original) while True: first = read_secret(prompt) @@ -154,8 +148,7 @@ while True: print(first) break - -tty_stream.close() +os.close(tty_fd) PY }