This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 2/2] linux ttyname_r: return link if appropriate
- From: Serge Hallyn <serge dot hallyn at ubuntu dot com>
- To: libc-alpha at sourceware dot org, Serge Hallyn <serge dot hallyn at ubuntu dot com>
- Date: Mon, 18 Apr 2016 19:53:49 +0000
- Subject: [PATCH 2/2] linux ttyname_r: return link if appropriate
- Authentication-results: sourceware.org; auth=none
- References: <20160415152929 dot GA7932 at ubuntumail> <5711165D dot 5040902 at redhat dot com> <20160415164652 dot GE8450 at ubuntumail> <57111F9C dot 8030902 at redhat dot com> <20160415174245 dot GA9610 at ubuntumail> <20160415184746 dot GA10830 at ubuntumail> <20160415195938 dot GP6588 at vapier dot lan>
Same as previous commit for ttyname
---
sysdeps/unix/sysv/linux/ttyname_r.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/sysdeps/unix/sysv/linux/ttyname_r.c b/sysdeps/unix/sysv/linux/ttyname_r.c
index d15bc74..e3d0c8b 100644
--- a/sysdeps/unix/sysv/linux/ttyname_r.c
+++ b/sysdeps/unix/sysv/linux/ttyname_r.c
@@ -32,6 +32,19 @@ static int getttyname_r (char *buf, size_t buflen,
dev_t mydev, ino64_t myino, int save,
int *dostat) internal_function;
+/* Return true if this is a UNIX98 pty device, as defined in
+ linux/Documentation/devices.txt */
+static int
+is_pty (struct stat64 *sb)
+{
+#ifdef _STATBUF_ST_RDEV
+ int m = major (sb->st_rdev);
+ return (136 <= m && m <= 143);
+#else
+ return false;
+#endif
+}
+
static int
internal_function attribute_compat_text_section
getttyname_r (char *buf, size_t buflen, dev_t mydev, ino64_t myino,
@@ -158,6 +171,15 @@ __ttyname_r (int fd, char *buf, size_t buflen)
#endif
)
return 0;
+
+ /* If the link doesn't exist, then it points to a device in another
+ namespace. If it is a UNIX98 pty, then return the /proc/self
+ fd, as it points to a name unreachable in our namespace */
+ if (is_pty (&st) && strlen (procname) < buflen - 1)
+ {
+ strcpy (buf, procname);
+ return 0;
+ }
}
/* Prepare the result buffer. */
--
2.7.4