Skip to content
Snippets Groups Projects
Commit 3023170f authored by Iustin Pop's avatar Iustin Pop
Browse files

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
parent 781b2b2b
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment