summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorRuben Herold <ruben@puettmann.net>2026-08-09 23:06:47 +0200
committerRuben Herold <ruben@puettmann.net>2026-08-09 23:06:47 +0200
commitb069ded58275ccb19d01b7dfa9944f27f0b4bb4d (patch)
tree0e5e208b1a0c8046b9929976d10d4139f1c5b3ec /python
parentf6a1ff94f02282bd018b9b49ae1a9812619ec7ba (diff)
downloadvyos-1x-b069ded58275ccb19d01b7dfa9944f27f0b4bb4d.tar.gz
vyos-1x-b069ded58275ccb19d01b7dfa9944f27f0b4bb4d.zip
utils: T9185: fix ask_yes_no() busy-looping forever on non-tty stdin
commit-confirm (and ~40 other call sites) hang and burn a full CPU core indefinitely when invoked with stdin that isn't a TTY, e.g. a non-interactive vbash session (vbash -c "... commit-confirm 10; exit"). input() raises EOFError immediately and repeatedly in that case, and the except handler in ask_yes_no() looped straight back to input() with no backoff or exit condition. Check stdin.isatty() up front and return the default immediately when it's not a TTY, matching what a user pressing Enter (accepting the default) would already do interactively.
Diffstat (limited to 'python')
-rw-r--r--python/vyos/utils/io.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/python/vyos/utils/io.py b/python/vyos/utils/io.py
index 77e30cbb0..13ef8709a 100644
--- a/python/vyos/utils/io.py
+++ b/python/vyos/utils/io.py
@@ -56,7 +56,10 @@ def ask_input(question, default='', numeric_only=False, valid_responses=[],
def ask_yes_no(question, default=False) -> bool:
"""Ask a yes/no question via input() and return their answer."""
- from sys import stdout
+ from sys import stdin, stdout
+
+ if not stdin.isatty():
+ return default
default_msg = "[Y/n]" if default else "[y/N]"
while True:
try: