[RFC PATCH] tty: flush buffer on signal interrupted tty close

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When a signal interrupts tty_wait_until_sent() on a UART device, there
might be data left on the xmit buffer that the UART will never transmit.
This causes set_termios() to wait forever in tty_wait_until_sent().

The hang reproduces easily on my system that is equipped with DesignWare
8250. Run

  while true; do echo -ne 0123456789abcdef01 > /dev/ttyS1; done

Hit Ctrl-C to interrupt the loop. When data is left in the struct
uart_state xmit buffer, the following command hangs:

  stty -F /dev/ttyS1 raw -echo

Call tty_driver_flush_buffer() on signal interrupted wait, to discard
data from the xmit buffer.

Signed-off-by: Baruch Siach <baruch@xxxxxxxxxx>
---
 drivers/tty/tty_ioctl.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index 507a25d692bb..0bf6fad7ecb3 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -203,6 +203,8 @@ void tty_wait_until_sent(struct tty_struct *tty, long timeout)
 
 	timeout = wait_event_interruptible_timeout(tty->write_wait,
 			!tty_chars_in_buffer(tty), timeout);
+	if (timeout == -ERESTARTSYS && tty->closing)
+		tty_driver_flush_buffer(tty);
 	if (timeout <= 0)
 		return;
 
-- 
2.33.0




[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux