Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tty: N_TTY SIGIO only works for read

The N_TTY ldisc layer does not send SIGIO POLL_OUTs correctly when output is
possible due to flawed handling of the TTY_DO_WRITE_WAKEUP bit. It will
either send no SIGIOs at all or on every tty wakeup.

The fix is to set the bit when the tty driver write would block and test
and clear it on write wakeup.

[Merged with existing N_TTY patches and a small buglet fixed -- Alan]

Signed-off-by: Thomas Pfaff <tpfaff@pcs.com>
Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Thomas Pfaff and committed by
Linus Torvalds
ff8cb0fd eff6937a

+3 -3
+3 -3
drivers/char/n_tty.c
··· 1352 1352 /* Write out any echoed characters that are still pending */ 1353 1353 process_echoes(tty); 1354 1354 1355 - if (tty->fasync) { 1356 - set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 1355 + if (tty->fasync && test_and_clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) 1357 1356 kill_fasync(&tty->fasync, SIGIO, POLL_OUT); 1358 - } 1359 1357 } 1360 1358 1361 1359 /** ··· 2012 2014 break_out: 2013 2015 __set_current_state(TASK_RUNNING); 2014 2016 remove_wait_queue(&tty->write_wait, &wait); 2017 + if (b - buf != nr && tty->fasync) 2018 + set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 2015 2019 return (b - buf) ? b - buf : retval; 2016 2020 } 2017 2021