uml: work around host tcsetattr bug

Under the conditions that UML uses it, tcgetattr is guaranteed to return
-EINTR when the console is attached to /dev/ptmx, making generic_console_write
hang because it loops, calling tcgetattr until it succeeds.  This is a host
bug - see http://marc.info/?l=linux-kernel&m=119618990807182&w=2 for the
details.

This patch works around it by blocking SIGIO while the terminal attributes are
being fiddled.

Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Jeff Dike 2007-12-01 12:16:30 -08:00 committed by Linus Torvalds
parent 0a765329ed
commit ce3b642d42
1 changed files with 10 additions and 1 deletions

View File

@ -74,10 +74,16 @@ void generic_free(void *data)
int generic_console_write(int fd, const char *buf, int n) int generic_console_write(int fd, const char *buf, int n)
{ {
sigset_t old, no_sigio;
struct termios save, new; struct termios save, new;
int err; int err;
if (isatty(fd)) { if (isatty(fd)) {
sigemptyset(&no_sigio);
sigaddset(&no_sigio, SIGIO);
if (sigprocmask(SIG_BLOCK, &no_sigio, &old))
goto error;
CATCH_EINTR(err = tcgetattr(fd, &save)); CATCH_EINTR(err = tcgetattr(fd, &save));
if (err) if (err)
goto error; goto error;
@ -97,8 +103,11 @@ int generic_console_write(int fd, const char *buf, int n)
* Restore raw mode, in any case; we *must* ignore any error apart * Restore raw mode, in any case; we *must* ignore any error apart
* EINTR, except for debug. * EINTR, except for debug.
*/ */
if (isatty(fd)) if (isatty(fd)) {
CATCH_EINTR(tcsetattr(fd, TCSAFLUSH, &save)); CATCH_EINTR(tcsetattr(fd, TCSAFLUSH, &save));
sigprocmask(SIG_SETMASK, &old, NULL);
}
return err; return err;
error: error:
return -errno; return -errno;