Bug#682972: ttyname() (and /bin/tty) on /dev/tty return "/dev/tty"
Ian Jackson writes ("ttyname() (and /bin/tty) on /dev/tty return "/dev/tty""):
> Package: libc6
> Version: 2.11.2-10
>
> ttyname() should return the name of the tty device in a form than can
> be used by other processes (with different controlling terminals) to
> open it.
Having considered and discussed this some more I think it will be
difficult to fix this without a kernel change.
Consider the following case:
$ exec 4<>/dev/tty
$ xterm&
[1] 15604
$
And then in the resulting xterm:
$ tty <&4
/dev/tty
$ echo hi >&4 [ prints hi on the original terminal, as expected ]
$ echo hi >`tty <&4`
hi [ this is wrong, it should go to the original terminal ]
$
AFAICT Linux (2.6.32-5-686-bigmem at least) don't provide any way to
get the right answer.
My friends report that the behaviour across other operating systems is
not consistent, but I think the behaviour we see here is clearly
wrong. (I don't know what Debian/kFreeBSD and Hurd do.)
SuSv3 says that ttyname returns
a string containing a null-terminated pathname of the terminal
associated with file descriptor fildes
I can't see how that can be satisfied by returning a pathname which,
when opened, gives a new descriptor referring to a different terminal.
(Notwithstanding the non-normative "Application Usage" section giving
"/dev/tty" as an example of a possible return value.)
There is similar problem with ctermid, which the glibc info manual
documents as always returning "/dev/tty".
Thanks,
Ian.
Reply to: