mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
tty: enable TCSETSF
While there is a difference between flavors of this ioctl (`TCSETS`, `TCSETSF`, `TCSETSW`), in practice it seems not to matter. We should let users call `TCSETSF` and can implement those differences if necessary.
This commit is contained in:
@@ -158,6 +158,10 @@ func (mfd *masterFileDescription) Ioctl(ctx context.Context, io usermem.IO, sysn
|
||||
case linux.TCSETSW:
|
||||
// TODO(b/29356795): This should drain the output queue first.
|
||||
return mfd.t.ld.setTermios(t, args)
|
||||
case linux.TCSETSF:
|
||||
// TODO(b/29356795): This should drain the output queue and
|
||||
// clear the input queue first.
|
||||
return mfd.t.ld.setTermios(t, args)
|
||||
case linux.TIOCGPTN:
|
||||
nP := primitive.Uint32(mfd.t.n)
|
||||
_, err := nP.CopyOut(t, args[2].Pointer())
|
||||
|
||||
@@ -170,6 +170,10 @@ func (rfd *replicaFileDescription) Ioctl(ctx context.Context, io usermem.IO, sys
|
||||
case linux.TCSETSW:
|
||||
// TODO(b/29356795): This should drain the output queue first.
|
||||
return rfd.inode.t.ld.setTermios(t, args)
|
||||
case linux.TCSETSF:
|
||||
// TODO(b/29356795): This should drain the output queue and
|
||||
// clear the input queue first.
|
||||
return rfd.inode.t.ld.setTermios(t, args)
|
||||
case linux.TIOCGPTN:
|
||||
nP := primitive.Uint32(rfd.inode.t.n)
|
||||
_, err := nP.CopyOut(t, args[2].Pointer())
|
||||
|
||||
@@ -777,6 +777,40 @@ TEST_F(PtyTest, TermiosONLCR) {
|
||||
ExpectFinished(replica_);
|
||||
}
|
||||
|
||||
// ICRNL rewrites input \r to \n.
|
||||
TEST_F(PtyTest, TCSETSFTermiosICRNL) {
|
||||
struct kernel_termios t = DefaultTermios();
|
||||
t.c_iflag |= ICRNL;
|
||||
t.c_lflag &= ~ICANON; // for byte-by-byte reading.
|
||||
ASSERT_THAT(ioctl(replica_.get(), TCSETSF, &t), SyscallSucceeds());
|
||||
|
||||
char c = '\r';
|
||||
ASSERT_THAT(WriteFd(master_.get(), &c, 1), SyscallSucceedsWithValue(1));
|
||||
|
||||
ExpectReadable(replica_, 1, &c);
|
||||
EXPECT_EQ(c, '\n');
|
||||
|
||||
ExpectFinished(replica_);
|
||||
}
|
||||
|
||||
// ONLCR rewrites output \n to \r\n.
|
||||
TEST_F(PtyTest, TCSETSFTermiosONLCR) {
|
||||
struct kernel_termios t = DefaultTermios();
|
||||
t.c_oflag |= ONLCR;
|
||||
t.c_lflag &= ~ICANON; // for byte-by-byte reading.
|
||||
ASSERT_THAT(ioctl(replica_.get(), TCSETSF, &t), SyscallSucceeds());
|
||||
|
||||
char c = '\n';
|
||||
ASSERT_THAT(WriteFd(replica_.get(), &c, 1), SyscallSucceedsWithValue(1));
|
||||
|
||||
// Extra byte for NUL for EXPECT_STREQ.
|
||||
char buf[3] = {};
|
||||
ExpectReadable(master_, 2, buf);
|
||||
EXPECT_STREQ(buf, "\r\n");
|
||||
|
||||
ExpectFinished(replica_);
|
||||
}
|
||||
|
||||
TEST_F(PtyTest, TermiosIGNCR) {
|
||||
struct kernel_termios t = DefaultTermios();
|
||||
t.c_iflag |= IGNCR;
|
||||
|
||||
Reference in New Issue
Block a user