* [Qemu-devel] [PATCH] Handle closed stdin/stdin from file.
@ 2003-09-19 6:59 Rusty Russell
0 siblings, 0 replies; only message in thread
From: Rusty Russell @ 2003-09-19 6:59 UTC (permalink / raw)
To: Fabrice Bellard; +Cc: qemu-devel
vl chews 100% of cpu in a polling loop when fd 0 is a file or closed.
Fix below.
Against 0.4.3, but you get the idea.
diff -ur qemu-0.4.3/vl.c qemu-0.4.3-umlswitch/vl.c
--- qemu-0.4.3/vl.c 2003-07-14 08:12:05.000000000 +1000
+++ qemu-0.4.3-umlswitch/vl.c 2003-09-18 14:48:55.000000000 +1000
@@ -2542,11 +2546,12 @@
void main_loop(void *opaque)
{
- struct pollfd ufds[2], *pf, *serial_ufd, *net_ufd, *gdb_ufd;
- int ret, n, timeout;
+ struct pollfd ufds[3], *pf, *serial_ufd, *net_ufd, *gdb_ufd;
+ int ret, n, timeout, serial_ok;
uint8_t ch;
CPUState *env = global_env;
+ serial_ok = 1;
for(;;) {
ret = cpu_x86_exec(env);
@@ -2559,12 +2564,12 @@
/* poll any events */
serial_ufd = NULL;
pf = ufds;
- if (!(serial_ports[0].lsr & UART_LSR_DR)) {
+ if (serial_ok && !(serial_ports[0].lsr & UART_LSR_DR)) {
serial_ufd = pf;
pf->fd = 0;
pf->events = POLLIN;
@@ -2588,7 +2593,11 @@
n = read(0, &ch, 1);
if (n == 1) {
serial_received_byte(&serial_ports[0], ch);
- }
+ } else {
+ /* Closed, stop polling. */
+ serial_ok = 0;
+ fprintf(stderr, "Ignoring closed serial port\n");
+ }
}
if (net_ufd && (net_ufd->revents & POLLIN)) {
uint8_t buf[MAX_ETH_FRAME_SIZE];
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2003-09-19 6:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-19 6:59 [Qemu-devel] [PATCH] Handle closed stdin/stdin from file Rusty Russell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).