Merge pull request #9339 from kevinGC:tcsetsf2

PiperOrigin-RevId: 563207341
This commit is contained in:
gVisor bot
2023-09-06 13:58:08 -07:00
3 changed files with 42 additions and 0 deletions
+4
View File
@@ -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())
+4
View File
@@ -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())
+34
View File
@@ -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;