Do not return ErrWouldBlock when writing nothing to PTY replica output

Previously, writing an empty string to the PTY replica output queue
would return linux.ErrWouldBlock. This PR fixes this behavior to
not return an error.
This commit is contained in:
Nathan Wang
2024-02-01 20:38:59 +00:00
parent a5f0778c38
commit 89c034566e
2 changed files with 21 additions and 5 deletions
+2 -5
View File
@@ -271,11 +271,8 @@ func (l *lineDiscipline) outputQueueWrite(ctx context.Context, src usermem.IOSeq
if err != nil {
return 0, err
}
if n > 0 {
l.masterWaiter.Notify(waiter.ReadableEvents)
return n, nil
}
return 0, linuxerr.ErrWouldBlock
l.masterWaiter.Notify(waiter.ReadableEvents)
return n, nil
}
// replicaOpen is called when a replica file descriptor is opened.
+19
View File
@@ -1384,6 +1384,25 @@ TEST_F(PtyTest, PartialBadBuffer) {
EXPECT_THAT(munmap(addr, 2 * kPageSize), SyscallSucceeds()) << addr;
}
// Test that writing nothing to the PTY replica's output queue does not return an error.
TEST_F(PtyTest, ReplicaWriteNothingCanonical) {
constexpr char kInput[] = "";
EXPECT_THAT(WriteFd(replica_.get(), kInput, strlen(kInput)),
SyscallSucceedsWithValue(strlen(kInput)));
ExpectFinished(master_);
}
TEST_F(PtyTest, ReplicaWriteNothingNonCanonical) {
DisableCanonical();
constexpr char kInput[] = "";
EXPECT_THAT(WriteFd(replica_.get(), kInput, strlen(kInput)),
SyscallSucceedsWithValue(strlen(kInput)));
ExpectFinished(master_);
}
TEST_F(PtyTest, SimpleEcho) {
constexpr char kInput[] = "Mr. Eko";
EXPECT_THAT(WriteFd(master_.get(), kInput, strlen(kInput)),