[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]

Fix for CPU-hogging rdesktops



When rdesktop is started by a button or menu choice in your
window manager (not from an xterm or similar), and the user logs
out of X without closing rdesktop first, rdesktop often hangs
and eats up all the available CPU. The following patch (also
attached) cures this:

diff -ru xwin.c.orig xwin.c
--- xwin.c.orig	Thu Aug 23 10:40:05 2001
+++ xwin.c	Fri Oct 19 15:07:18 2001
@@ -666,6 +751,11 @@
             ui_ungrab_keyboard();
           break;
 	}
+    }
+
+  if (ui_pending() && XNextEvent(display, &event))
+    {
+      DEBUG ("Got event type %d\n", event.type);
     }
 }


The reason why rdesktop hangs is that the ui_process_events()
(which is called as long as there is events in the X event
queue) only checks for (and removes) events related to the
rdesktop window.

When logging out of X without exiting rdesktop, rdesktop will
receive a "Oops, connection to X server broken" event. This
event will never be removed from the event queue (it's not
related to a specific window), and the result is that
ui_process_events() gets called over and over again (but doing
nothing), hogging the CPU.

With this patch, rdesktop exits "cleanly" with the usual message
"X connection to :2.1 broken (explicit kill or server shutdown)."
if it loses its connection with the X server.


-- 
Per Kristian Hove <Per.Hove@math.ntnu.no>
Principal engineer
Dept. of Mathematical Sciences
Norwegian University of Science and Technology
diff -ru xwin.c.orig xwin.c
--- xwin.c.orig	Thu Aug 23 10:40:05 2001
+++ xwin.c	Fri Oct 19 15:07:18 2001
@@ -666,6 +751,11 @@
             ui_ungrab_keyboard();
           break;
 	}
+    }
+
+  if (ui_pending() && XNextEvent(display, &event))
+    {
+      DEBUG ("Got event type %d\n", event.type);
     }
 }