diff options
author | Christian Brauner <christian.brauner@ubuntu.com> | 2017-03-22 18:16:52 +0100 |
---|---|---|
committer | Amadeusz Sławiński <amade@asmblr.net> | 2017-03-24 14:01:27 +0100 |
commit | 78d2a73273786bd7c5f3be481b23a5bee19dc519 (patch) | |
tree | 0cecbff74ea07c9912a274f8bbdb16f33abcbda4 | |
parent | 12a4b7c4071c5f6eb63ec1ecd0fbad41943e4ce3 (diff) | |
download | screen-78d2a73273786bd7c5f3be481b23a5bee19dc519.tar.gz |
handle pty device from different namespace
Various programs that deal with namespaces will use pty devices that exist in
another namespace. One obvious candiate are containers. So far ttyname() was
incorrectly handling this case because the pts device stems from the host and
thus cannot be found amongst the current namespace's /dev/pts/<n> entries.
Serge Hallyn and I recently upstreamed patches to glibc that allow ttyname{_r}()
to correctly handle this case. At a minimum, ttyname{_r}() will set errno to
ENODEV in case it finds that the /dev/pts/<n> device that the symlink points to
exists in another namespace. This commit will allow screen to handle this case
and behave correctly in a container.
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
-rw-r--r-- | src/screen.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/screen.c b/src/screen.c index 6cd528a..14aaa33 100644 --- a/src/screen.c +++ b/src/screen.c @@ -981,18 +981,26 @@ int main(int ac, char** av) #define SET_TTYNAME(fatal) do \ { \ + int saved_errno = 0; \ + errno = 0; \ if (!(attach_tty = ttyname(0))) \ { \ - if (fatal) \ + /* stdin is a tty but it exists in another namespace. */ \ + if (fatal && errno == ENODEV) \ + attach_tty = ""; \ + else if (fatal) \ Panic(0, "Must be connected to a terminal."); \ else \ attach_tty = ""; \ } \ else \ { \ + saved_errno = errno; \ if (stat(attach_tty, &st)) \ Panic(errno, "Cannot access '%s'", attach_tty); \ - if (CheckTtyname(attach_tty)) \ + /* Only call CheckTtyname() if the device does not exist in another \ + * namespace. */ \ + if (saved_errno != ENODEV && CheckTtyname(attach_tty)) \ Panic(0, "Bad tty '%s'", attach_tty); \ } \ if (strlen(attach_tty) >= MAXPATHLEN) \ |