public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Dmitry V. Levin" <ldv@altlinux.org>
To: Christian Brauner <christian.brauner@canonical.com>
Cc: libc-alpha@sourceware.org, Serge Hallyn <serge@hallyn.com>
Subject: Re: [PATCH] linux ttyname and ttyname_r: do not return wrong results
Date: Tue, 22 Nov 2016 02:10:00 -0000	[thread overview]
Message-ID: <20161122020948.GA21837@altlinux.org> (raw)
In-Reply-To: <20161108165638.21674-2-christian.brauner@canonical.com>

On Tue, Nov 08, 2016 at 05:56:38PM +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@canonical.com>
> ---
> Changelog: 2016-11-08
> 	- remove obsolete comment in ttyname_r.c
> 	- move is_pty() to common header file and mark as static inline
> ---
>  sysdeps/unix/sysv/linux/ttyname.c   | 17 +++++++++++++----
>  sysdeps/unix/sysv/linux/ttyname.h   | 35 +++++++++++++++++++++++++++++++++++
>  sysdeps/unix/sysv/linux/ttyname_r.c | 18 ++++++++++++++----
>  3 files changed, 62 insertions(+), 8 deletions(-)
>  create mode 100644 sysdeps/unix/sysv/linux/ttyname.h
> 
> diff --git a/sysdeps/unix/sysv/linux/ttyname.c b/sysdeps/unix/sysv/linux/ttyname.c
> index 7a001b4..dabed22 100644
> --- a/sysdeps/unix/sysv/linux/ttyname.c
> +++ b/sysdeps/unix/sysv/linux/ttyname.c
> @@ -25,9 +25,12 @@
>  #include <unistd.h>
>  #include <string.h>
>  #include <stdlib.h>
> +#include <sys/sysmacros.h>

This is probably a leftover from previous editions and could be safely removed.

[...]
> diff --git a/sysdeps/unix/sysv/linux/ttyname_r.c b/sysdeps/unix/sysv/linux/ttyname_r.c
> index d15bc74..542114b 100644
> --- a/sysdeps/unix/sysv/linux/ttyname_r.c
> +++ b/sysdeps/unix/sysv/linux/ttyname_r.c
> @@ -25,9 +25,12 @@
>  #include <unistd.h>
>  #include <string.h>
>  #include <stdlib.h>
> +#include <sys/sysmacros.h>

Likewise.

Besides that, it looks good.


-- 
ldv

  parent reply	other threads:[~2016-11-22  2:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-08 16:56 Christian Brauner
2016-11-08 16:56 ` Christian Brauner
2016-11-10 18:04   ` Serge E. Hallyn
2016-11-22  2:10   ` Dmitry V. Levin [this message]
2016-11-22  0:14 ` Christian Brauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161122020948.GA21837@altlinux.org \
    --to=ldv@altlinux.org \
    --cc=christian.brauner@canonical.com \
    --cc=libc-alpha@sourceware.org \
    --cc=serge@hallyn.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).