[PATCH] linux ttyname and ttyname_r: return link if appropriate
Dmitry V. Levin
ldv@altlinux.org
Wed Jul 27 17:28:00 GMT 2016
On Wed, Apr 20, 2016 at 06:51:41PM +0000, Serge Hallyn wrote:
> 1. If the passed-in link (say /proc/self/fd/0) points to a
> device, say /dev/pts/2, in a parent mount namespace, and a
> /dev/pts/2 exists (in a different devpts) in the current
> namespace, then it returns /dev/pts/2. But /dev/pts/2 is
> NOT the current tty, it is a different file and device.
[...]
> --- a/sysdeps/unix/sysv/linux/ttyname.c
> +++ b/sysdeps/unix/sysv/linux/ttyname.c
[...]
> @@ -170,12 +184,19 @@ ttyname (int fd)
> #ifdef _STATBUF_ST_RDEV
> && S_ISCHR (st1.st_mode)
> && st1.st_rdev == st.st_rdev
> + && st1.st_dev == st.st_dev
> #else
> && st1.st_ino == st.st_ino
> && st1.st_dev == st.st_dev
> #endif
__ttyname_r also needs this st_dev check.
To be on the safe side, I'd check st_ino in _STATBUF_ST_RDEV case as well.
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20160727/c285e7c1/attachment.sig>
More information about the Libc-alpha
mailing list