Skip to content

Commit

Permalink
tty: fallback to open /dev/ptmx on EACCES
Browse files Browse the repository at this point in the history
Some distros like to set /dev/pts/ptmx to mode 0000 for some reason;
this commit makes --tty work in these environments.
  • Loading branch information
Snaipe committed Jun 14, 2021
1 parent f111c51 commit c4046bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions test/tty.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Allocate a PTY for the spacetime

Check that redirections still work

$ echo hello | bst --tty --mount devpts,/dev/pts,devpts,mode=620,ptmxmode=666 cat
$ echo hello | bst --tty cat
hello
hello

$ bst --tty --mount devpts,/dev/pts,devpts,mode=620,ptmxmode=666 echo hello | cat
$ bst --tty echo hello | cat
hello
10 changes: 9 additions & 1 deletion tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,15 @@ void tty_child(int socket)
{
int mfd = open("/dev/pts/ptmx", O_RDWR | O_NONBLOCK);
if (mfd < 0) {
err(1, "tty_child: open ptmx");
if (errno == EACCES) {
/* Special case: some distros configure /dev/pts/ptmx to be mode
0000 as a way to force the use of /dev/ptmx. Fallback to that
so that it works as expected when not changing roots. */
mfd = open("/dev/ptmx", O_RDWR | O_NONBLOCK);
}
if (mfd == -1) {
err(1, "tty_child: open ptmx");
}
}
int unlock = 0;
if (ioctl(mfd, TIOCSPTLCK, &unlock) < 0) {
Expand Down

0 comments on commit c4046bc

Please sign in to comment.