linux: Fix CPU usage bug in console fd flushing

Submitted by Adam Jackson on Aug. 25, 2010, 10:09 p.m.

Details

Message ID 1282748959-32003-1-git-send-email-ajax@redhat.com
State Accepted, archived
Commit a6b9e8f1e5d5d0b3b0f121a6f677eeca7aab1950
Headers show

Not browsing as part of any series.

Commit Message

Adam Jackson Aug. 25, 2010, 10:09 p.m.
If the vt gets a vhangup from under us, then the tty will appear ready
in select(), but trying to tcflush() it will return -EIO, so we'll spin
around at 100% CPU for no reason.  Notice this condition and unregister
the handler if it happens.

Signed-off-by: Adam Jackson <ajax@redhat.com>
---
 hw/xfree86/os-support/linux/lnx_init.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

Patch hide | download patch | download mbox

diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c
index c8cec2e..21f2220 100644
--- a/hw/xfree86/os-support/linux/lnx_init.c
+++ b/hw/xfree86/os-support/linux/lnx_init.c
@@ -85,7 +85,11 @@  static void *console_handler;
 static void
 drain_console(int fd, void *closure)
 {
-    tcflush(fd, TCIOFLUSH);
+    errno = 0;
+    if (tcflush(fd, TCIOFLUSH) == -1 && errno == EIO) {
+	xf86RemoveGeneralHandler(console_handler);
+	console_handler = NULL;
+    }
 }
 
 void

Comments

On Wed, Aug 25, 2010 at 11:09:19 -0400, Adam Jackson wrote:

> If the vt gets a vhangup from under us, then the tty will appear ready
> in select(), but trying to tcflush() it will return -EIO, so we'll spin
> around at 100% CPU for no reason.  Notice this condition and unregister
> the handler if it happens.
> 
> Signed-off-by: Adam Jackson <ajax@redhat.com>

Reviewed-by: Julien Cristau <jcristau@debian.org>

I remember people getting in that loop a while ago due to some
interactions with upstart stealing the console from under X, I think.

Cheers,
Julien