Skip to content
  • Iustin Pop's avatar
    Fix AskUser to not die on extra input · 3023170f
    Iustin Pop authored
    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
    3023170f