ttyname() and linux+devfs
Zack Weinberg
zack@rabi.columbia.edu
Thu Oct 29 15:47:00 GMT 1998
On Thu, 29 Oct 1998 22:54:04 +0100 (MET), Clifford Wolf wrote:
>
>On Thu, 29 Oct 1998, Martin von Loewis wrote:
>
>> > /dev/vc/*, my cua devices are /dev/cua/* and so on. It would be great if
>> > the ttyname function could make a recursive scan thru the compleate /dev
>> > directory structure instead of lokking only in /dev/ and /dev/pts/.
>>
>> Why not use /proc/self/fd/0 instead?
>
>That's a good question. Why don't making just a readlink() on
>/proc/self/fd/%d (where %d is the fd number)? Would be much faster
>than scanning /dev and works with all /dev structures ...
>
>It would solve the symlink/real-device problem too: afaik the symlinks
>in /proc/self/fd/ point to the filenames which are passed to open() - and
>this are the filenames we would like to know.
It's not a bad idea, but there are several problems. /proc isn't
guaranteed to be there. In 2.0, the /proc/self/fd files are not
normal symlinks. It can be misled if you do something like
ttyname(open("/dev/tty")) /* get real name of controlling terminal? */
although I'm not sure that works now.
This is one of those Hard Problems.
zw
More information about the Libc-alpha
mailing list