From: Manfred Spraul <manfred@colorfullife.com>

Eli Barzilay noticed that select() for tty devices is broken: For 
stopped tty devices, select says POLLOUT and write fails with -EAGAIN.

http://marc.theaimsgroup.com/?l=linux-kernel&m=105902461110282&w=2

I've tracked this back to normal_poll in drivers/char/n_tty.c:

 > if (tty->driver->chars_in_buffer(tty) < WAKEUP_CHARS)
 >                mask |= POLLOUT | POLLWRNORM;

It assumes that a following write will succeed if less than 256 bytes 
are in the write buffer right now. This assumption is wrong for 
con_write_room: if the console is stopped, it returns 0 bytes buffer 
size (con_write_room()). Dito for pty_write_room.


 25-akpm/drivers/char/n_tty.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletion(-)

diff -puN drivers/char/n_tty.c~select-xoffed-tty-fix drivers/char/n_tty.c
--- 25/drivers/char/n_tty.c~select-xoffed-tty-fix	Mon Jul 28 12:04:51 2003
+++ 25-akpm/drivers/char/n_tty.c	Mon Jul 28 12:04:51 2003
@@ -1251,7 +1251,8 @@ static unsigned int normal_poll(struct t
 		else
 			tty->minimum_to_wake = 1;
 	}
-	if (tty->driver->chars_in_buffer(tty) < WAKEUP_CHARS)
+	if (tty->driver->chars_in_buffer(tty) < WAKEUP_CHARS &&
+			tty->driver->write_room(tty) > 0)
 		mask |= POLLOUT | POLLWRNORM;
 	return mask;
 }

_