Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.22) id 1A0FFH-0004Iq-R6 for qemu-devel@nongnu.org; Fri, 19 Sep 2003 02:59:59 -0400 Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.22) id 1A0FFG-0004HU-A4 for qemu-devel@nongnu.org; Fri, 19 Sep 2003 02:59:58 -0400 Received: from [66.70.73.150] (helo=lists.samba.org) by monty-python.gnu.org with esmtp (Exim 4.22) id 1A0FFG-0004Gp-1Z for qemu-devel@nongnu.org; Fri, 19 Sep 2003 02:59:58 -0400 From: Rusty Russell Date: Fri, 19 Sep 2003 16:59:11 +1000 Sender: rusty@bach.samba.org Message-Id: <20030919065957.63DB82C017@lists.samba.org> Subject: [Qemu-devel] [PATCH] Handle closed stdin/stdin from file. Reply-To: qemu-devel@nongnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fabrice Bellard Cc: qemu-devel@nongnu.org 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.