From 3023170fe8d7f8c0de823a858c3ef229fa2a427b Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Wed, 10 Oct 2007 14:04:51 +0000 Subject: [PATCH] Fix AskUser to not die on extra input Currently, AskUser dies with -ESPIPE if the user gives more than one character plus newline. This is because the python library, while returning only two chars from the readline(2) call, will cache the rest of the input, and when we do a write, it will try to seek back to just after the last returned char. This fails on /dev/tty, so an exception is raised. However, then opening the file descriptor in O_APPEND mode, python will not issue such seeks, thereby fixing this problem. The other alternative, opening in unbuffered mode, is not as good, since then python will issue one-byte reads at a time, but the tty will read the entire line, so at the next readline call, whatever remained in the descriptor buffer is returned from the kernel to python, and the user doesn't get a chance to enter something at all. Reviewed-by: imsnah --- lib/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli.py b/lib/cli.py index 9a6784d..85606d4 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -311,7 +311,7 @@ def AskUser(text, choices=None): new_text.append(textwrap.fill(line, 70, replace_whitespace=False)) text = "\n".join(new_text) try: - f = file("/dev/tty", "r+") + f = file("/dev/tty", "a+") except IOError: return answer try: -- 1.7.10.4