qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] Handle closed stdin/stdin from file.


From: Rusty Russell
Subject: [Qemu-devel] [PATCH] Handle closed stdin/stdin from file.
Date: Fri, 19 Sep 2003 16:59:11 +1000

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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]