From patchwork Tue Nov 12 08:43:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 290553 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CBF232C00B1 for ; Tue, 12 Nov 2013 19:44:10 +1100 (EST) Received: from localhost ([::1]:41676 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vg9Zv-0002wr-VC for incoming@patchwork.ozlabs.org; Tue, 12 Nov 2013 03:44:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60207) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vg9Zc-0002sS-Bg for qemu-devel@nongnu.org; Tue, 12 Nov 2013 03:43:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vg9ZW-000661-8G for qemu-devel@nongnu.org; Tue, 12 Nov 2013 03:43:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:15950) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vg9ZV-00065x-Up for qemu-devel@nongnu.org; Tue, 12 Nov 2013 03:43:42 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rAC8heBH001662 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 12 Nov 2013 03:43:40 -0500 Received: from nilsson.home.kraxel.org (vpn1-4-183.ams2.redhat.com [10.36.4.183]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rAC8hdEn021908; Tue, 12 Nov 2013 03:43:39 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 2D40380479; Tue, 12 Nov 2013 09:43:38 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 12 Nov 2013 09:43:34 +0100 Message-Id: <1384245814-15010-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann , Anthony Liguori Subject: [Qemu-devel] [PATCH] curses: fixup SIGWINCH handler mess X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Reviewed-by: Laszlo Ersek --- ui/curses.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/ui/curses.c b/ui/curses.c index 289a955..c33acff 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 bool 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;