Running the following command in Bash 4,
sudo prompts for a password:
$ echo '' | sudo true [sudo] password for mike:
(I'm not interested in piping my password to
sudo; this is a demonstration of a behavior I found while troubleshooting.)
It's been my understanding that TTY detection takes place through inspection of
the file descriptor for standard in. The
tty program supports this:
$ tty /dev/pts/26 $ echo '' | tty not a tty
sudo seems to be using some other mechanism.
setsid has the intended effect, so my guess is that this is somehow tied to the session.
$ setsid sudo true sudo: no tty present and no askpass program specified
So what is
sudo up to?