Fix data race in tty.queue.readableSize.

We were setting queue.readable without holding the lock.

PiperOrigin-RevId: 290306922
This commit is contained in:
Nicolas Lacasse
2020-01-17 11:22:10 -08:00
committed by gVisor bot
parent 8e8d0f96f6
commit 80d0f93044
2 changed files with 5 additions and 10 deletions
+3 -1
View File
@@ -140,8 +140,10 @@ func (l *lineDiscipline) setTermios(ctx context.Context, io usermem.IO, args arc
// buffer to its read buffer. Anything already in the read buffer is
// now readable.
if oldCanonEnabled && !l.termios.LEnabled(linux.ICANON) {
l.inQueue.pushWaitBuf(l)
l.inQueue.mu.Lock()
l.inQueue.pushWaitBufLocked(l)
l.inQueue.readable = true
l.inQueue.mu.Unlock()
l.slaveWaiter.Notify(waiter.EventIn)
}
+2 -9
View File
@@ -197,16 +197,9 @@ func (q *queue) writeBytes(b []byte, l *lineDiscipline) {
q.pushWaitBufLocked(l)
}
// pushWaitBuf fills the queue's read buffer with data from the wait buffer.
// pushWaitBufLocked fills the queue's read buffer with data from the wait
// buffer.
//
// Preconditions:
// * l.termiosMu must be held for reading.
func (q *queue) pushWaitBuf(l *lineDiscipline) int {
q.mu.Lock()
defer q.mu.Unlock()
return q.pushWaitBufLocked(l)
}
// Preconditions:
// * l.termiosMu must be held for reading.
// * q.mu must be locked.