]> git.baikalelectronics.ru Git - kernel.git/commit
tty: Fix pty master poll() after slave closes v2
authorFrancesco Ruggeri <fruggeri@aristanetworks.com>
Fri, 10 Oct 2014 20:09:53 +0000 (13:09 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 6 Nov 2014 20:23:36 +0000 (12:23 -0800)
commit11c84e15936efc3165b8788964a846b01568cdcb
tree93241c8332a47a765bc8338415c8b9e7996049a0
parent3cf7b938bf4039c60a578533f32bb535f6621239
tty: Fix pty master poll() after slave closes v2

Commit 7a354a5f2bdf ("n_tty: Don't wait for buffer work in read() loop")
introduces a race window where a pty master can be signalled that the pty
slave was closed before all the data that the slave wrote is delivered.
Commit 2524cc787e0f ("tty: Fix pty master read() after slave closes") fixed the
problem in case of n_tty_read, but the problem still exists for n_tty_poll.
This can be seen by running 'for ((i=0; i<100;i++));do ./test.py ;done'
where test.py is:

import os, select, pty

(pid, pty_fd) = pty.fork()

if pid == 0:
   os.write(1, 'This string should be received by parent')
else:
   poller = select.epoll()
   poller.register( pty_fd, select.EPOLLIN )
   ready = poller.poll( 1 * 1000 )
   for fd, events in ready:
      if not events & select.EPOLLIN:
         print 'missed POLLIN event'
      else:
         print os.read(fd, 100)
   poller.close()

The string from the slave is missed several times.
This patch takes the same approach as the fix for read and special cases
this condition for poll.
Tested on 3.16.

Signed-off-by: Francesco Ruggeri <fruggeri@arista.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/n_tty.c