浏览代码

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>
Thomas Pfaff 16 年之前
父节点
当前提交
ff8cb0fd6f
共有 1 个文件被更改,包括 3 次插入3 次删除
  1. 3 3
      drivers/char/n_tty.c

+ 3 - 3
drivers/char/n_tty.c

@@ -1352,10 +1352,8 @@ static void n_tty_write_wakeup(struct tty_struct *tty)
 	/* Write out any echoed characters that are still pending */
 	/* Write out any echoed characters that are still pending */
 	process_echoes(tty);
 	process_echoes(tty);
 
 
-	if (tty->fasync) {
-		set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+	if (tty->fasync && test_and_clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags))
 		kill_fasync(&tty->fasync, SIGIO, POLL_OUT);
 		kill_fasync(&tty->fasync, SIGIO, POLL_OUT);
-	}
 }
 }
 
 
 /**
 /**
@@ -2014,6 +2012,8 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
 break_out:
 break_out:
 	__set_current_state(TASK_RUNNING);
 	__set_current_state(TASK_RUNNING);
 	remove_wait_queue(&tty->write_wait, &wait);
 	remove_wait_queue(&tty->write_wait, &wait);
+	if (b - buf != nr && tty->fasync)
+		set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
 	return (b - buf) ? b - buf : retval;
 	return (b - buf) ? b - buf : retval;
 }
 }