faketty
faketty copied to clipboard
Reading from /dev/tty
(This might be expected/as designed)
If the program run inside the PTY tries to open and read from the controlling terminal via /dev/tty
things don't work quite right, but worse they don't fail as expected either.
Context
This is easiest to see with sudo
which tries to open /dev/tty
in order to write the prompt ("Password: "
) as well as reading the response from the user directly from the controlling terminal. If opening /dev/tty
with O_RDWR
fails it falls back to using stdin/stderr which work ask expected with faketty
. All this can be seen in tgetpass.c
of sudo
if interested.
However with faketty
opening /dev/tty
works just fine, and even writing to it works as expected, but reading from it does not appear to work.
Example, the password is echo'ed and sending a newline does nothing:
$ faketty sudo whoami
Password: foobarbaz
^C
$
However, forcing sudo
to use stderr/stdin works as expected
$ faketty sudo -S whoami
Password:
root
$
Question
Is not being able to read from the controlling terminal expected, or is there anything that could be done in this case to set up the controlling terminal to allow reading?