From patchwork Wed Jan 21 15:51:21 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Bloch X-Patchwork-Id: 3476 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n0LFolZh027944 for ; Wed, 21 Jan 2009 07:50:48 -0800 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752631AbZAUPzH (ORCPT ); Wed, 21 Jan 2009 10:55:07 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754725AbZAUPzH (ORCPT ); Wed, 21 Jan 2009 10:55:07 -0500 Received: from main.gmane.org ([80.91.229.2]:52073 "EHLO ciao.gmane.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752631AbZAUPzF (ORCPT ); Wed, 21 Jan 2009 10:55:05 -0500 Received: from root by ciao.gmane.org with local (Exim 4.43) id 1LPfPy-000209-BJ for kvm@vger.kernel.org; Wed, 21 Jan 2009 15:55:02 +0000 Received: from desk3.office.bytemark.co.uk ([89.16.168.152]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 21 Jan 2009 15:55:02 +0000 Received: from matthew by desk3.office.bytemark.co.uk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 21 Jan 2009 15:55:02 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: kvm@vger.kernel.org From: Matthew Bloch Subject: [PATCH] Fix freezing bug in curses console Date: Wed, 21 Jan 2009 15:51:21 +0000 Lines: 82 Message-ID: Mime-Version: 1.0 X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: desk3.office.bytemark.co.uk User-Agent: Thunderbird 2.0.0.19 (X11/20090105) Cc: qemu-devel@nongnu.org Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Hi there, We are running lots of kvm processes in screen and found that about 1 in 5 froze shortly after startup startup with a backtrace like this one: #0 0xf7c7fcd9 in pthread_exit () from /lib/tls/libc.so.6 #1 0xf7cfbe62 in wresize () from /lib/libncurses.so.5 #2 0xf7cfb7ab in is_term_resized () from /lib/libncurses.so.5 #3 0xf7cfb877 in is_term_resized () from /lib/libncurses.so.5 #4 0xf7cfba31 in resize_term () from /lib/libncurses.so.5 #5 0x080d3dd9 in vga_init () #6 #7 0xf7c0da5b in free () from /lib/tls/libc.so.6 #8 0xf7c0effe in calloc () from /lib/tls/libc.so.6 #9 0xf7cf222e in newpad () from /lib/libncurses.so.5 #10 0x080d3549 in vga_init () We're just using the lenny version of kvm from 2008-12-16. On casual inspection, the SIGWINCH signal handling looked ropey to me - grandpa always told me not to do any real work in a signal handler, and the backtrace suggested re-entrancy problems in curses, so I changed the behaviour to set a flag and do the work in the main loop instead. Maybe I'm reading the backtrace wrong. So far that means that when you resize the window, the display is corrupt until the VM outputs some text, or the user hits a key. But I think it has solved the freezing / crashing bug too - would appreciate any comments on my analysis or proposed solution. Index: curses.c =================================================================== --- curses.c (revision 6374) +++ curses.c (working copy) @@ -41,6 +41,7 @@ #define FONT_HEIGHT 16 #define FONT_WIDTH 8 +static int winch_flag = 0; static console_ch_t screen[160 * 100]; static WINDOW *screenpad = NULL; static int width, height, gwidth, gheight, invalidate; @@ -110,7 +111,7 @@ #ifndef _WIN32 #if defined(SIGWINCH) && defined(KEY_RESIZE) -static void curses_winch_handler(int signum) +static void curses_winch_handler_real(void) { struct winsize { unsigned short ws_row; @@ -126,7 +127,13 @@ resize_term(ws.ws_row, ws.ws_col); curses_calc_pad(); invalidate = 1; + winch_flag = 0; +} +static void curses_winch_handler(int sig) +{ + winch_flag = 1; + /* some systems require this */ signal(SIGWINCH, curses_winch_handler); } @@ -179,6 +186,12 @@ s nextchr = ERR; while (1) { + +#if !defined(_WIN32) && defined(SIGWINCH) && defined(KEY_RESIZE) + if (winch_flag) + curses_winch_handler_real(); +#endif + /* while there are any pending key strokes to process */ if (nextchr == ERR) chr = getch();