[PATCH v3] linux ttyname and ttyname_r: do not return wrong results
Dmitry V. Levin
ldv@altlinux.org
Thu Nov 24 09:55:00 GMT 2016
On Thu, Nov 24, 2016 at 02:32:36AM +0100, Christian Brauner wrote:
> If a link (say /proc/self/fd/0) pointing to a device, say /dev/pts/2, in a
> parent mount namespace is passed to ttyname, 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.
>
> Detect this case and return ENODEV. Userspace can choose to take this as a hint
> that the fd points to a tty device but to act on the fd rather than the link.
>
> Signed-off-by: Serge Hallyn <serge@hallyn.com>
> Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
> ---
> Changelog: 2016-11-08
> - remove obsolete comment in ttyname_r.c
> - move is_pty() to common header file and mark as static inline
> Changelog: 2016-11-22
> - remove unneeded sys/symacros.h header
> Changelog: 2016-11-24
> - add Changelog entry
> ---
> ChangeLog | 8 ++++++++
> sysdeps/unix/sysv/linux/ttyname.c | 16 ++++++++++++----
> sysdeps/unix/sysv/linux/ttyname.h | 35 +++++++++++++++++++++++++++++++++++
> sysdeps/unix/sysv/linux/ttyname_r.c | 17 +++++++++++++----
> 4 files changed, 68 insertions(+), 8 deletions(-)
> create mode 100644 sysdeps/unix/sysv/linux/ttyname.h
>
> diff --git a/ChangeLog b/ChangeLog
> index b6fc831..c236992 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,11 @@
> +2016-11-23 Christian Brauner <christian.brauner@ubuntu.com>
> +
> + * sysdeps/unix/sysv/linux/ttyname.c: do not return wrong results when
> + detecting tty devices residing in a different namespace
> + * sysdeps/unix/sysv/linux/ttyname_r.c: do not return wrong results when
> + detecting tty devices residing in a different namespace
> + * sysdeps/unix/sysv/linux/ttyname.h: New file
This doesn't quite follow the style guidelines. A properly formatted
ChangeLog for this change would look like this:
2016-11-24 Christian Brauner <christian.brauner@ubuntu.com>
* sysdeps/unix/sysv/linux/ttyname.h: New file.
* sysdeps/unix/sysv/linux/ttyname.c: Include "ttyname.h".
(ttyname) [!_STATBUF_ST_RDEV]: Make code unconditional.
Call is_pty when the link does not exist or does not match, fail
with ENODEV when it returns true.
* sysdeps/unix/sysv/linux/ttyname_r.c: Include "ttyname.h".
(__ttyname_r) [!_STATBUF_ST_RDEV]: Make code unconditional.
Call is_pty when the link does not exist or does not match, fail
with ENODEV when it returns true.
--
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/20161124/519473f1/attachment.sig>
More information about the Libc-alpha
mailing list