From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44175) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vj8sq-0002da-04 for qemu-devel@nongnu.org; Wed, 20 Nov 2013 09:36:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vj8sd-0002a0-2Z for qemu-devel@nongnu.org; Wed, 20 Nov 2013 09:35:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:25465) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vj8sc-0002ZI-JG for qemu-devel@nongnu.org; Wed, 20 Nov 2013 09:35:46 -0500 From: Gerd Hoffmann Date: Wed, 20 Nov 2013 15:35:22 +0100 Message-Id: <1384958128-22878-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1384958128-22878-1-git-send-email-kraxel@redhat.com> References: <1384958128-22878-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH v2] curses: fixup SIGWINCH handler mess List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Anthony Liguori Don't run code in the signal handler, only set a flag. Use sigaction(2) to avoid non-portable signal(2) semantics. Make #ifdefs less messy. Signed-off-by: Gerd Hoffmann --- ui/curses.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/ui/curses.c b/ui/curses.c index 289a955..dbc3d5e 100644 --- a/ui/curses.c +++ b/ui/curses.c @@ -106,9 +106,9 @@ static void curses_resize(DisplayChangeListener *dcl, curses_calc_pad(); } -#ifndef _WIN32 -#if defined(SIGWINCH) && defined(KEY_RESIZE) -static void curses_winch_handler(int signum) +#if !defined(_WIN32) && defined(SIGWINCH) && defined(KEY_RESIZE) +static volatile sig_atomic_t got_sigwinch; +static void curses_winch_check(void) { struct winsize { unsigned short ws_row; @@ -117,18 +117,34 @@ static void curses_winch_handler(int signum) unsigned short ws_ypixel; /* unused */ } ws; - /* terminal size changed */ - if (ioctl(1, TIOCGWINSZ, &ws) == -1) + if (!got_sigwinch) { + return; + } + got_sigwinch = false; + + if (ioctl(1, TIOCGWINSZ, &ws) == -1) { return; + } resize_term(ws.ws_row, ws.ws_col); - curses_calc_pad(); invalidate = 1; +} - /* some systems require this */ - signal(SIGWINCH, curses_winch_handler); +static void curses_winch_handler(int signum) +{ + got_sigwinch = true; } -#endif + +static void curses_winch_init(void) +{ + struct sigaction old, winch = { + .sa_handler = curses_winch_handler, + }; + sigaction(SIGWINCH, &winch, &old); +} +#else +static void curses_winch_check(void) {} +static void curses_winch_init(void) {} #endif static void curses_cursor_position(DisplayChangeListener *dcl, @@ -163,6 +179,8 @@ static void curses_refresh(DisplayChangeListener *dcl) { int chr, nextchr, keysym, keycode, keycode_alt; + curses_winch_check(); + if (invalidate) { clear(); refresh(); @@ -349,13 +367,7 @@ void curses_display_init(DisplayState *ds, int full_screen) curses_keyboard_setup(); atexit(curses_atexit); -#ifndef _WIN32 -#if defined(SIGWINCH) && defined(KEY_RESIZE) - /* some curses implementations provide a handler, but we - * want to be sure this is handled regardless of the library */ - signal(SIGWINCH, curses_winch_handler); -#endif -#endif + curses_winch_init(); dcl = (DisplayChangeListener *) g_malloc0(sizeof(DisplayChangeListener)); dcl->ops = &dcl_ops; -- 1.8.3.1