]> git.baikalelectronics.ru Git - kernel.git/commit
tty: Fix pty master read() after slave closes
authorPeter Hurley <peter@hurleysoftware.com>
Fri, 27 Sep 2013 17:27:05 +0000 (13:27 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 1 Oct 2013 02:05:56 +0000 (19:05 -0700)
commit2524cc787e0f817025d6f6041305c16faf72a660
tree5d3fbaa52d7967a924f790f1d0cb363a7ed0f498
parent4b334a65369be36ee55758dc198154c20d226294
tty: Fix pty master read() after slave closes

Commit 7a354a5f2bdfb768a963bb2376b7a1725ae0fec1,
  n_tty: Don't wait for buffer work in read() loop
creates a race window which can cause a pty master read()
to miss the last pty slave write(s) and return -EIO instead,
thus signalling the pty slave is closed. This can happen when
the pty slave is written and immediately closed but before the
tty buffer i/o loop receives the new input; the pty master
read() is scheduled, sees its read buffer is empty and the
pty slave has been closed, and exits.

Because tty_flush_to_ldisc() has significant performance impact
for parallel i/o, rather than revert the commit, special case this
condition (ie., when the read buffer is empty and the 'other' pty
has been closed) and, only then, wait for buffer work to complete
before re-testing if the read buffer is still empty.

As before, subsequent pty master reads return any available data
until no more data is available, and then returns -EIO to
indicate the pty slave has closed.

Reported-by: Mikael Pettersson <mikpelinux@gmail.com>
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Tested-by: Mikael Pettersson <mikpelinux@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/n_tty.c