2018-01-01 01:32:25 +01:00
|
|
|
/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 06:58:11 +02:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 06:58:11 +02:00
|
|
|
Lesser General Public License for more details.
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
|
2001-07-06 06:58:11 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-10 00:18:22 +01:00
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2006-12-05 22:28:15 +01:00
|
|
|
#include <termios.h>
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2012-03-21 00:00:23 +01:00
|
|
|
#include <_itoa.h>
|
1998-10-29 16:17:25 +01:00
|
|
|
|
2017-01-27 15:59:59 +01:00
|
|
|
#include "ttyname.h"
|
|
|
|
|
2000-05-23 10:43:26 +02:00
|
|
|
static int getttyname_r (char *buf, size_t buflen,
|
linux ttyname{_r}: Make tty checks consistent
In the ttyname and ttyname_r routines on Linux, at several points it needs to
check if a given TTY is the TTY we are looking for. It used to be that this
check was (to see if `maybe` is `mytty`):
__xstat64(_STAT_VER, maybe_filename, &maybe) == 0
#ifdef _STATBUF_ST_RDEV
&& S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
#else
&& maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev
#endif
This check appears in several places.
Then, one of the changes made in commit 15e9a4f378c8607c2ae1aa465436af4321db0e23
was to change that check to:
__xstat64(_STAT_VER, maybe_filename, &maybe) == 0
#ifdef _STATBUF_ST_RDEV
&& S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
#endif
&& maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev
That is, it made the st_ino and st_dev parts of the check happen even if we have
the st_rdev member. This is an important change, because the kernel allows
multiple devpts filesystem instances to be created; a device file in one devpts
instance may share the same st_rdev with a file in another devpts instance, but
they aren't the same file.
This check appears twice in each file (ttyname.c and ttyname_r.c), once (in
ttyname and __ttyname_r) to check if a candidate file found by inspecting /proc
is the desired TTY, and once (in getttyname and getttyname_r) to check if a
candidate file found by searching /dev is the desired TTY. However, 15e9a4f
only updated the checks for files found via /proc; but the concern about
collisions between devpts instances is just as valid for files found via /dev.
So, update all 4 occurrences the check to be consistent with the version of the
check introduced in 15e9a4f. Make it easy to keep all 4 occurrences of the
check consistent by pulling it in to a static inline function, is_mytty.
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-15 20:34:30 +01:00
|
|
|
const struct stat64 *mytty, int save,
|
2017-08-31 18:25:55 +02:00
|
|
|
int *dostat);
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
|
|
|
|
static int
|
2017-08-31 18:25:55 +02:00
|
|
|
attribute_compat_text_section
|
linux ttyname{_r}: Make tty checks consistent
In the ttyname and ttyname_r routines on Linux, at several points it needs to
check if a given TTY is the TTY we are looking for. It used to be that this
check was (to see if `maybe` is `mytty`):
__xstat64(_STAT_VER, maybe_filename, &maybe) == 0
#ifdef _STATBUF_ST_RDEV
&& S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
#else
&& maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev
#endif
This check appears in several places.
Then, one of the changes made in commit 15e9a4f378c8607c2ae1aa465436af4321db0e23
was to change that check to:
__xstat64(_STAT_VER, maybe_filename, &maybe) == 0
#ifdef _STATBUF_ST_RDEV
&& S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
#endif
&& maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev
That is, it made the st_ino and st_dev parts of the check happen even if we have
the st_rdev member. This is an important change, because the kernel allows
multiple devpts filesystem instances to be created; a device file in one devpts
instance may share the same st_rdev with a file in another devpts instance, but
they aren't the same file.
This check appears twice in each file (ttyname.c and ttyname_r.c), once (in
ttyname and __ttyname_r) to check if a candidate file found by inspecting /proc
is the desired TTY, and once (in getttyname and getttyname_r) to check if a
candidate file found by searching /dev is the desired TTY. However, 15e9a4f
only updated the checks for files found via /proc; but the concern about
collisions between devpts instances is just as valid for files found via /dev.
So, update all 4 occurrences the check to be consistent with the version of the
check introduced in 15e9a4f. Make it easy to keep all 4 occurrences of the
check consistent by pulling it in to a static inline function, is_mytty.
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-15 20:34:30 +01:00
|
|
|
getttyname_r (char *buf, size_t buflen, const struct stat64 *mytty,
|
2000-05-23 10:43:26 +02:00
|
|
|
int save, int *dostat)
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
{
|
2000-09-01 04:26:05 +02:00
|
|
|
struct stat64 st;
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
DIR *dirstream;
|
2001-02-13 23:17:17 +01:00
|
|
|
struct dirent64 *d;
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
size_t devlen = strlen (buf);
|
|
|
|
|
1998-07-16 13:44:36 +02:00
|
|
|
dirstream = __opendir (buf);
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
if (dirstream == NULL)
|
|
|
|
{
|
|
|
|
*dostat = -1;
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
|
2001-02-13 23:17:17 +01:00
|
|
|
while ((d = __readdir64 (dirstream)) != NULL)
|
linux ttyname{_r}: Make tty checks consistent
In the ttyname and ttyname_r routines on Linux, at several points it needs to
check if a given TTY is the TTY we are looking for. It used to be that this
check was (to see if `maybe` is `mytty`):
__xstat64(_STAT_VER, maybe_filename, &maybe) == 0
#ifdef _STATBUF_ST_RDEV
&& S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
#else
&& maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev
#endif
This check appears in several places.
Then, one of the changes made in commit 15e9a4f378c8607c2ae1aa465436af4321db0e23
was to change that check to:
__xstat64(_STAT_VER, maybe_filename, &maybe) == 0
#ifdef _STATBUF_ST_RDEV
&& S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
#endif
&& maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev
That is, it made the st_ino and st_dev parts of the check happen even if we have
the st_rdev member. This is an important change, because the kernel allows
multiple devpts filesystem instances to be created; a device file in one devpts
instance may share the same st_rdev with a file in another devpts instance, but
they aren't the same file.
This check appears twice in each file (ttyname.c and ttyname_r.c), once (in
ttyname and __ttyname_r) to check if a candidate file found by inspecting /proc
is the desired TTY, and once (in getttyname and getttyname_r) to check if a
candidate file found by searching /dev is the desired TTY. However, 15e9a4f
only updated the checks for files found via /proc; but the concern about
collisions between devpts instances is just as valid for files found via /dev.
So, update all 4 occurrences the check to be consistent with the version of the
check introduced in 15e9a4f. Make it easy to keep all 4 occurrences of the
check consistent by pulling it in to a static inline function, is_mytty.
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-15 20:34:30 +01:00
|
|
|
if ((d->d_fileno == mytty->st_ino || *dostat)
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
&& strcmp (d->d_name, "stdin")
|
|
|
|
&& strcmp (d->d_name, "stdout")
|
|
|
|
&& strcmp (d->d_name, "stderr"))
|
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
size_t needed = _D_EXACT_NAMLEN (d) + 1;
|
|
|
|
|
|
|
|
if (needed > buflen)
|
|
|
|
{
|
|
|
|
*dostat = -1;
|
1998-07-16 13:44:36 +02:00
|
|
|
(void) __closedir (dirstream);
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
__set_errno (ERANGE);
|
|
|
|
return ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cp = __stpncpy (buf + devlen, d->d_name, needed);
|
|
|
|
cp[0] = '\0';
|
|
|
|
|
2000-09-01 04:26:05 +02:00
|
|
|
if (__xstat64 (_STAT_VER, buf, &st) == 0
|
linux ttyname{_r}: Make tty checks consistent
In the ttyname and ttyname_r routines on Linux, at several points it needs to
check if a given TTY is the TTY we are looking for. It used to be that this
check was (to see if `maybe` is `mytty`):
__xstat64(_STAT_VER, maybe_filename, &maybe) == 0
#ifdef _STATBUF_ST_RDEV
&& S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
#else
&& maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev
#endif
This check appears in several places.
Then, one of the changes made in commit 15e9a4f378c8607c2ae1aa465436af4321db0e23
was to change that check to:
__xstat64(_STAT_VER, maybe_filename, &maybe) == 0
#ifdef _STATBUF_ST_RDEV
&& S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
#endif
&& maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev
That is, it made the st_ino and st_dev parts of the check happen even if we have
the st_rdev member. This is an important change, because the kernel allows
multiple devpts filesystem instances to be created; a device file in one devpts
instance may share the same st_rdev with a file in another devpts instance, but
they aren't the same file.
This check appears twice in each file (ttyname.c and ttyname_r.c), once (in
ttyname and __ttyname_r) to check if a candidate file found by inspecting /proc
is the desired TTY, and once (in getttyname and getttyname_r) to check if a
candidate file found by searching /dev is the desired TTY. However, 15e9a4f
only updated the checks for files found via /proc; but the concern about
collisions between devpts instances is just as valid for files found via /dev.
So, update all 4 occurrences the check to be consistent with the version of the
check introduced in 15e9a4f. Make it easy to keep all 4 occurrences of the
check consistent by pulling it in to a static inline function, is_mytty.
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-15 20:34:30 +01:00
|
|
|
&& is_mytty (mytty, &st))
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
{
|
1998-07-16 13:44:36 +02:00
|
|
|
(void) __closedir (dirstream);
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
__set_errno (save);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-16 13:44:36 +02:00
|
|
|
(void) __closedir (dirstream);
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
__set_errno (save);
|
|
|
|
/* It is not clear what to return in this case. `isatty' says FD
|
|
|
|
refers to a TTY but no entry in /dev has this inode. */
|
|
|
|
return ENOTTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store at most BUFLEN character of the pathname of the terminal FD is
|
|
|
|
open on in BUF. Return 0 on success, otherwise an error number. */
|
|
|
|
int
|
2000-05-23 10:43:26 +02:00
|
|
|
__ttyname_r (int fd, char *buf, size_t buflen)
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
{
|
1998-10-29 16:17:25 +01:00
|
|
|
char procname[30];
|
2000-09-01 04:26:05 +02:00
|
|
|
struct stat64 st, st1;
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
int dostat = 0;
|
linux ttyname{_r}: Don't bail prematurely [BZ #22145]
Commit 15e9a4f378c8607c2ae1aa465436af4321db0e23 introduced logic for ttyname()
sending back ENODEV to signal that we can't get a name for the TTY because we
inherited it from a different mount namespace.
However, just because we inherited it from a different mount namespace and it
isn't available at its original path, doesn't mean that its name is unknowable;
we can still try to find it by allowing the normal fall back on iterating
through devices.
An example scenario where this happens is with "/dev/console" in containers.
It's a common practice among container managers to allocate a PTY master/slave
pair in the host's mount namespace (the slave having a path like "/dev/pty/$X"),
bind mount the slave to "/dev/console" in the container's mount namespace, and
send the slave FD to a process in the container. Inside of the
container, the slave-end isn't available at its original path ("/dev/pts/$X"),
since the container mount namespace has a separate devpts instance from the host
(that path may or may not exist in the container; if it does exist, it's not the
same PTY slave device). Currently ttyname{_r} sees that the file at the
original "/dev/pts/$X" path doesn't match the FD passed to it, and fails early
and gives up, even though if it kept searching it would find the TTY at
"/dev/console". Fix that; don't have the ENODEV path force an early return
inhibiting the fall-back search.
This change is based on the previous patch that adds use of is_mytty in
getttyname and getttyname_r. Without that change, this effectively reverts
15e9a4f, which made us disregard the false similarity of file pointed to by
"/proc/self/fd/$Y", because if it doesn't bail prematurely then that file
("/dev/pts/$X") will just come up again anyway in the fall-back search.
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-15 20:36:44 +01:00
|
|
|
int doispty = 0;
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
int save = errno;
|
|
|
|
|
|
|
|
/* Test for the absolute minimal size. This makes life easier inside
|
|
|
|
the loop. */
|
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
__set_errno (EINVAL);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buflen < sizeof ("/dev/pts/"))
|
|
|
|
{
|
|
|
|
__set_errno (ERANGE);
|
|
|
|
return ERANGE;
|
|
|
|
}
|
|
|
|
|
2006-12-05 22:28:15 +01:00
|
|
|
/* isatty check, tcgetattr is used because it sets the correct
|
|
|
|
errno (EBADF resp. ENOTTY) on error. */
|
|
|
|
struct termios term;
|
2014-02-10 14:45:42 +01:00
|
|
|
if (__glibc_unlikely (__tcgetattr (fd, &term) < 0))
|
2006-12-05 22:28:15 +01:00
|
|
|
return errno;
|
2006-04-19 09:27:58 +02:00
|
|
|
|
2010-11-03 05:25:45 +01:00
|
|
|
if (__fxstat64 (_STAT_VER, fd, &st) < 0)
|
|
|
|
return errno;
|
|
|
|
|
2003-02-18 22:04:15 +01:00
|
|
|
/* We try using the /proc filesystem. */
|
|
|
|
*_fitoa_word (fd, __stpcpy (procname, "/proc/self/fd/"), 10, 0) = '\0';
|
|
|
|
|
2006-04-19 09:27:58 +02:00
|
|
|
ssize_t ret = __readlink (procname, buf, buflen - 1);
|
2014-02-10 14:45:42 +01:00
|
|
|
if (__glibc_unlikely (ret == -1 && errno == ENAMETOOLONG))
|
2003-02-18 22:04:15 +01:00
|
|
|
{
|
|
|
|
__set_errno (ERANGE);
|
|
|
|
return ERANGE;
|
|
|
|
}
|
1998-10-29 16:17:25 +01:00
|
|
|
|
2014-02-10 14:45:42 +01:00
|
|
|
if (__glibc_likely (ret != -1))
|
1999-04-01 11:33:06 +02:00
|
|
|
{
|
2010-11-03 05:25:45 +01:00
|
|
|
#define UNREACHABLE_LEN strlen ("(unreachable)")
|
|
|
|
if (ret > UNREACHABLE_LEN
|
|
|
|
&& memcmp (buf, "(unreachable)", UNREACHABLE_LEN) == 0)
|
|
|
|
{
|
|
|
|
memmove (buf, buf + UNREACHABLE_LEN, ret - UNREACHABLE_LEN);
|
|
|
|
ret -= UNREACHABLE_LEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readlink need not terminate the string. */
|
1999-04-01 11:33:06 +02:00
|
|
|
buf[ret] = '\0';
|
1998-10-29 16:17:25 +01:00
|
|
|
|
2010-11-03 05:25:45 +01:00
|
|
|
/* Verify readlink result, fall back on iterating through devices. */
|
|
|
|
if (buf[0] == '/'
|
|
|
|
&& __xstat64 (_STAT_VER, buf, &st1) == 0
|
linux ttyname{_r}: Make tty checks consistent
In the ttyname and ttyname_r routines on Linux, at several points it needs to
check if a given TTY is the TTY we are looking for. It used to be that this
check was (to see if `maybe` is `mytty`):
__xstat64(_STAT_VER, maybe_filename, &maybe) == 0
#ifdef _STATBUF_ST_RDEV
&& S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
#else
&& maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev
#endif
This check appears in several places.
Then, one of the changes made in commit 15e9a4f378c8607c2ae1aa465436af4321db0e23
was to change that check to:
__xstat64(_STAT_VER, maybe_filename, &maybe) == 0
#ifdef _STATBUF_ST_RDEV
&& S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
#endif
&& maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev
That is, it made the st_ino and st_dev parts of the check happen even if we have
the st_rdev member. This is an important change, because the kernel allows
multiple devpts filesystem instances to be created; a device file in one devpts
instance may share the same st_rdev with a file in another devpts instance, but
they aren't the same file.
This check appears twice in each file (ttyname.c and ttyname_r.c), once (in
ttyname and __ttyname_r) to check if a candidate file found by inspecting /proc
is the desired TTY, and once (in getttyname and getttyname_r) to check if a
candidate file found by searching /dev is the desired TTY. However, 15e9a4f
only updated the checks for files found via /proc; but the concern about
collisions between devpts instances is just as valid for files found via /dev.
So, update all 4 occurrences the check to be consistent with the version of the
check introduced in 15e9a4f. Make it easy to keep all 4 occurrences of the
check consistent by pulling it in to a static inline function, is_mytty.
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-15 20:34:30 +01:00
|
|
|
&& is_mytty (&st, &st1))
|
2010-11-03 05:25:45 +01:00
|
|
|
return 0;
|
2017-01-27 15:59:59 +01:00
|
|
|
|
linux ttyname{_r}: Don't bail prematurely [BZ #22145]
Commit 15e9a4f378c8607c2ae1aa465436af4321db0e23 introduced logic for ttyname()
sending back ENODEV to signal that we can't get a name for the TTY because we
inherited it from a different mount namespace.
However, just because we inherited it from a different mount namespace and it
isn't available at its original path, doesn't mean that its name is unknowable;
we can still try to find it by allowing the normal fall back on iterating
through devices.
An example scenario where this happens is with "/dev/console" in containers.
It's a common practice among container managers to allocate a PTY master/slave
pair in the host's mount namespace (the slave having a path like "/dev/pty/$X"),
bind mount the slave to "/dev/console" in the container's mount namespace, and
send the slave FD to a process in the container. Inside of the
container, the slave-end isn't available at its original path ("/dev/pts/$X"),
since the container mount namespace has a separate devpts instance from the host
(that path may or may not exist in the container; if it does exist, it's not the
same PTY slave device). Currently ttyname{_r} sees that the file at the
original "/dev/pts/$X" path doesn't match the FD passed to it, and fails early
and gives up, even though if it kept searching it would find the TTY at
"/dev/console". Fix that; don't have the ENODEV path force an early return
inhibiting the fall-back search.
This change is based on the previous patch that adds use of is_mytty in
getttyname and getttyname_r. Without that change, this effectively reverts
15e9a4f, which made us disregard the false similarity of file pointed to by
"/proc/self/fd/$Y", because if it doesn't bail prematurely then that file
("/dev/pts/$X") will just come up again anyway in the fall-back search.
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-15 20:36:44 +01:00
|
|
|
doispty = 1;
|
2010-11-03 05:25:45 +01:00
|
|
|
}
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
|
|
|
|
/* Prepare the result buffer. */
|
|
|
|
memcpy (buf, "/dev/pts/", sizeof ("/dev/pts/"));
|
|
|
|
buflen -= sizeof ("/dev/pts/") - 1;
|
|
|
|
|
2000-09-01 04:26:05 +02:00
|
|
|
if (__xstat64 (_STAT_VER, buf, &st1) == 0 && S_ISDIR (st1.st_mode))
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
{
|
linux ttyname{_r}: Make tty checks consistent
In the ttyname and ttyname_r routines on Linux, at several points it needs to
check if a given TTY is the TTY we are looking for. It used to be that this
check was (to see if `maybe` is `mytty`):
__xstat64(_STAT_VER, maybe_filename, &maybe) == 0
#ifdef _STATBUF_ST_RDEV
&& S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
#else
&& maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev
#endif
This check appears in several places.
Then, one of the changes made in commit 15e9a4f378c8607c2ae1aa465436af4321db0e23
was to change that check to:
__xstat64(_STAT_VER, maybe_filename, &maybe) == 0
#ifdef _STATBUF_ST_RDEV
&& S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
#endif
&& maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev
That is, it made the st_ino and st_dev parts of the check happen even if we have
the st_rdev member. This is an important change, because the kernel allows
multiple devpts filesystem instances to be created; a device file in one devpts
instance may share the same st_rdev with a file in another devpts instance, but
they aren't the same file.
This check appears twice in each file (ttyname.c and ttyname_r.c), once (in
ttyname and __ttyname_r) to check if a candidate file found by inspecting /proc
is the desired TTY, and once (in getttyname and getttyname_r) to check if a
candidate file found by searching /dev is the desired TTY. However, 15e9a4f
only updated the checks for files found via /proc; but the concern about
collisions between devpts instances is just as valid for files found via /dev.
So, update all 4 occurrences the check to be consistent with the version of the
check introduced in 15e9a4f. Make it easy to keep all 4 occurrences of the
check consistent by pulling it in to a static inline function, is_mytty.
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-15 20:34:30 +01:00
|
|
|
ret = getttyname_r (buf, buflen, &st, save,
|
1999-03-08 12:46:22 +01:00
|
|
|
&dostat);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__set_errno (save);
|
|
|
|
ret = ENOENT;
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret && dostat != -1)
|
|
|
|
{
|
|
|
|
buf[sizeof ("/dev/") - 1] = '\0';
|
|
|
|
buflen += sizeof ("pts/") - 1;
|
linux ttyname{_r}: Make tty checks consistent
In the ttyname and ttyname_r routines on Linux, at several points it needs to
check if a given TTY is the TTY we are looking for. It used to be that this
check was (to see if `maybe` is `mytty`):
__xstat64(_STAT_VER, maybe_filename, &maybe) == 0
#ifdef _STATBUF_ST_RDEV
&& S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
#else
&& maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev
#endif
This check appears in several places.
Then, one of the changes made in commit 15e9a4f378c8607c2ae1aa465436af4321db0e23
was to change that check to:
__xstat64(_STAT_VER, maybe_filename, &maybe) == 0
#ifdef _STATBUF_ST_RDEV
&& S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
#endif
&& maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev
That is, it made the st_ino and st_dev parts of the check happen even if we have
the st_rdev member. This is an important change, because the kernel allows
multiple devpts filesystem instances to be created; a device file in one devpts
instance may share the same st_rdev with a file in another devpts instance, but
they aren't the same file.
This check appears twice in each file (ttyname.c and ttyname_r.c), once (in
ttyname and __ttyname_r) to check if a candidate file found by inspecting /proc
is the desired TTY, and once (in getttyname and getttyname_r) to check if a
candidate file found by searching /dev is the desired TTY. However, 15e9a4f
only updated the checks for files found via /proc; but the concern about
collisions between devpts instances is just as valid for files found via /dev.
So, update all 4 occurrences the check to be consistent with the version of the
check introduced in 15e9a4f. Make it easy to keep all 4 occurrences of the
check consistent by pulling it in to a static inline function, is_mytty.
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-15 20:34:30 +01:00
|
|
|
ret = getttyname_r (buf, buflen, &st, save,
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
&dostat);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret && dostat != -1)
|
|
|
|
{
|
|
|
|
buf[sizeof ("/dev/") - 1] = '\0';
|
|
|
|
dostat = 1;
|
linux ttyname{_r}: Make tty checks consistent
In the ttyname and ttyname_r routines on Linux, at several points it needs to
check if a given TTY is the TTY we are looking for. It used to be that this
check was (to see if `maybe` is `mytty`):
__xstat64(_STAT_VER, maybe_filename, &maybe) == 0
#ifdef _STATBUF_ST_RDEV
&& S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
#else
&& maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev
#endif
This check appears in several places.
Then, one of the changes made in commit 15e9a4f378c8607c2ae1aa465436af4321db0e23
was to change that check to:
__xstat64(_STAT_VER, maybe_filename, &maybe) == 0
#ifdef _STATBUF_ST_RDEV
&& S_ISCHR(maybe.st_mode) && maybe.st_rdev == mytty.st_rdev
#endif
&& maybe.st_ino == mytty.st_ino && maybe.st_dev == mytty.st_dev
That is, it made the st_ino and st_dev parts of the check happen even if we have
the st_rdev member. This is an important change, because the kernel allows
multiple devpts filesystem instances to be created; a device file in one devpts
instance may share the same st_rdev with a file in another devpts instance, but
they aren't the same file.
This check appears twice in each file (ttyname.c and ttyname_r.c), once (in
ttyname and __ttyname_r) to check if a candidate file found by inspecting /proc
is the desired TTY, and once (in getttyname and getttyname_r) to check if a
candidate file found by searching /dev is the desired TTY. However, 15e9a4f
only updated the checks for files found via /proc; but the concern about
collisions between devpts instances is just as valid for files found via /dev.
So, update all 4 occurrences the check to be consistent with the version of the
check introduced in 15e9a4f. Make it easy to keep all 4 occurrences of the
check consistent by pulling it in to a static inline function, is_mytty.
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-15 20:34:30 +01:00
|
|
|
ret = getttyname_r (buf, buflen, &st,
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
save, &dostat);
|
|
|
|
}
|
|
|
|
|
linux ttyname{_r}: Don't bail prematurely [BZ #22145]
Commit 15e9a4f378c8607c2ae1aa465436af4321db0e23 introduced logic for ttyname()
sending back ENODEV to signal that we can't get a name for the TTY because we
inherited it from a different mount namespace.
However, just because we inherited it from a different mount namespace and it
isn't available at its original path, doesn't mean that its name is unknowable;
we can still try to find it by allowing the normal fall back on iterating
through devices.
An example scenario where this happens is with "/dev/console" in containers.
It's a common practice among container managers to allocate a PTY master/slave
pair in the host's mount namespace (the slave having a path like "/dev/pty/$X"),
bind mount the slave to "/dev/console" in the container's mount namespace, and
send the slave FD to a process in the container. Inside of the
container, the slave-end isn't available at its original path ("/dev/pts/$X"),
since the container mount namespace has a separate devpts instance from the host
(that path may or may not exist in the container; if it does exist, it's not the
same PTY slave device). Currently ttyname{_r} sees that the file at the
original "/dev/pts/$X" path doesn't match the FD passed to it, and fails early
and gives up, even though if it kept searching it would find the TTY at
"/dev/console". Fix that; don't have the ENODEV path force an early return
inhibiting the fall-back search.
This change is based on the previous patch that adds use of is_mytty in
getttyname and getttyname_r. Without that change, this effectively reverts
15e9a4f, which made us disregard the false similarity of file pointed to by
"/proc/self/fd/$Y", because if it doesn't bail prematurely then that file
("/dev/pts/$X") will just come up again anyway in the fall-back search.
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-15 20:36:44 +01:00
|
|
|
if (ret && doispty && is_pty (&st))
|
|
|
|
{
|
|
|
|
/* We failed to figure out the TTY's name, but we can at least
|
|
|
|
signal that we did verify that it really is a PTY slave.
|
|
|
|
This happens when we have inherited the file descriptor from
|
|
|
|
a different mount namespace. */
|
|
|
|
__set_errno (ENODEV);
|
|
|
|
return ENODEV;
|
|
|
|
}
|
|
|
|
|
Update.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* streams/Makefile (headers): Add sys/stropts.h.
* streams/sys/stropts.h: New file.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ttyname.c,
sysdeps/unix/sysv/linux/ttyname_r.c: New files, like
sysdeps/posix/ttyname*.c, but look in /dev/pts first.
1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second
argument of _itoa_word.
1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents,
s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set
caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending,
sigprocmask, resp., instead of EXTRA.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
s_pread64 and s_pwrite64.
1998-04-27 11:43:55 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
weak_alias (__ttyname_r, ttyname_r)
|