Skip to content

Commit be939ce

Browse files
nlacassegvisor-bot
authored andcommitted
HACK to make /dev/tty work.
We need to plumb the host.TTYFileDescription into the /dev/tty device file. This is *not* the correct way to do it, but it does allow emacs to work. Updates #10925 DO NOT SUBMIT PiperOrigin-RevId: 676585154
1 parent 49310d9 commit be939ce

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

pkg/sentry/devices/ttydev/ttydev.go

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import (
2222
"gvisor.dev/gvisor/pkg/sentry/vfs"
2323
)
2424

25+
// TTYFile is a HACK.
26+
var TTYFile *vfs.FileDescription
27+
2528
const (
2629
// See drivers/tty/tty_io.c:tty_init().
2730
ttyDevMinor = 0
@@ -35,6 +38,9 @@ type ttyDevice struct{}
3538

3639
// Open implements vfs.Device.Open.
3740
func (ttyDevice) Open(ctx context.Context, mnt *vfs.Mount, vfsd *vfs.Dentry, opts vfs.OpenOptions) (*vfs.FileDescription, error) {
41+
if TTYFile != nil {
42+
return TTYFile, nil
43+
}
3844
return nil, linuxerr.EIO
3945
}
4046

pkg/sentry/fdimport/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ go_library(
1414
deps = [
1515
"//pkg/context",
1616
"//pkg/fd",
17+
"//pkg/sentry/devices/ttydev",
1718
"//pkg/sentry/fsimpl/host",
1819
"//pkg/sentry/kernel",
1920
"//pkg/sentry/kernel/auth",

pkg/sentry/fdimport/fdimport.go

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"golang.org/x/sys/unix"
2222
"gvisor.dev/gvisor/pkg/context"
2323
"gvisor.dev/gvisor/pkg/fd"
24+
"gvisor.dev/gvisor/pkg/sentry/devices/ttydev"
2425
"gvisor.dev/gvisor/pkg/sentry/fsimpl/host"
2526
"gvisor.dev/gvisor/pkg/sentry/kernel"
2627
"gvisor.dev/gvisor/pkg/sentry/kernel/auth"
@@ -106,6 +107,8 @@ func Import(ctx context.Context, fdTable *kernel.FDTable, console bool, uid auth
106107
if ttyFile == nil {
107108
return nil, nil
108109
}
110+
// HACK.
111+
ttydev.TTYFile = ttyFile
109112
return ttyFile.Impl().(*host.TTYFileDescription), nil
110113
}
111114

0 commit comments

Comments
 (0)