diff options
author | Kevin Krakauer <krakauer@google.com> | 2021-02-11 11:06:56 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-02-11 11:09:22 -0800 |
commit | ae8d966f5af0bba9978a1aedac64038ef65a4cc9 (patch) | |
tree | c6540f92ac18e178dcd0189302ee94e13c12b3d6 /test/util | |
parent | 192780946fdf584c5e504b24f47dbd9bd411a3a6 (diff) |
Assign controlling terminal when tty is opened and support NOCTTY
PiperOrigin-RevId: 357015186
Diffstat (limited to 'test/util')
-rw-r--r-- | test/util/pty_util.cc | 7 | ||||
-rw-r--r-- | test/util/pty_util.h | 8 |
2 files changed, 13 insertions, 2 deletions
diff --git a/test/util/pty_util.cc b/test/util/pty_util.cc index 2cf0bea74..351f4730c 100644 --- a/test/util/pty_util.cc +++ b/test/util/pty_util.cc @@ -24,11 +24,16 @@ namespace gvisor { namespace testing { PosixErrorOr<FileDescriptor> OpenReplica(const FileDescriptor& master) { + return OpenReplica(master, O_NONBLOCK | O_RDWR | O_NOCTTY); +} + +PosixErrorOr<FileDescriptor> OpenReplica(const FileDescriptor& master, + int flags) { PosixErrorOr<int> n = ReplicaID(master); if (!n.ok()) { return PosixErrorOr<FileDescriptor>(n.error()); } - return Open(absl::StrCat("/dev/pts/", n.ValueOrDie()), O_RDWR | O_NONBLOCK); + return Open(absl::StrCat("/dev/pts/", n.ValueOrDie()), flags); } PosixErrorOr<int> ReplicaID(const FileDescriptor& master) { diff --git a/test/util/pty_util.h b/test/util/pty_util.h index ed7658868..0cca2182c 100644 --- a/test/util/pty_util.h +++ b/test/util/pty_util.h @@ -21,9 +21,15 @@ namespace gvisor { namespace testing { -// Opens the replica end of the passed master as R/W and nonblocking. +// Opens the replica end of the passed master as R/W and nonblocking. It does +// not set the replica as the controlling TTY. PosixErrorOr<FileDescriptor> OpenReplica(const FileDescriptor& master); +// Identical to the above OpenReplica, but flags are all specified by the +// caller. +PosixErrorOr<FileDescriptor> OpenReplica(const FileDescriptor& master, + int flags); + // Get the number of the replica end of the master. PosixErrorOr<int> ReplicaID(const FileDescriptor& master); |