From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-bn3nam01on0127.outbound.protection.outlook.com ([104.47.33.127]:53399 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753156AbeA1W3t (ORCPT ); Sun, 28 Jan 2018 17:29:49 -0500 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Jiri Olsa , Adrian Hunter , Andi Kleen , David Ahern , "Namhyung Kim" , Wang Nan , "Arnaldo Carvalho de Melo" , Sasha Levin Subject: [PATCH AUTOSEL for 4.4 06/36] perf top: Fix window dimensions change handling Date: Sun, 28 Jan 2018 22:28:26 +0000 Message-ID: <20180128222815.29479-6-alexander.levin@microsoft.com> References: <20180128222815.29479-1-alexander.levin@microsoft.com> In-Reply-To: <20180128222815.29479-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Jiri Olsa [ Upstream commit 89d0aeab4252adc2a7ea693637dd21c588bfa2d1 ] The stdio perf top crashes when we change the terminal window size. The reason is that we assumed we get the perf_top pointer as a signal handler argument which is not the case. Changing the SIGWINCH handler logic to change global resize variable, which is checked in the main thread loop. Signed-off-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Tested-by: Ravi Bangoria Cc: Adrian Hunter Cc: Andi Kleen Cc: David Ahern Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-ysuzwz77oev1ftgvdscn9bpu@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/builtin-top.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 4a8a02c302d2..47719bde34c6 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -70,6 +70,7 @@ #include =20 static volatile int done; +static volatile int resize; =20 #define HEADER_LINE_NR 5 =20 @@ -79,10 +80,13 @@ static void perf_top__update_print_entries(struct perf_= top *top) } =20 static void perf_top__sig_winch(int sig __maybe_unused, - siginfo_t *info __maybe_unused, void *arg) + siginfo_t *info __maybe_unused, void *arg __maybe_unused) { - struct perf_top *top =3D arg; + resize =3D 1; +} =20 +static void perf_top__resize(struct perf_top *top) +{ get_term_dimensions(&top->winsize); perf_top__update_print_entries(top); } @@ -466,7 +470,7 @@ static bool perf_top__handle_keypress(struct perf_top *= top, int c) .sa_sigaction =3D perf_top__sig_winch, .sa_flags =3D SA_SIGINFO, }; - perf_top__sig_winch(SIGWINCH, NULL, top); + perf_top__resize(top); sigaction(SIGWINCH, &act, NULL); } else { signal(SIGWINCH, SIG_DFL); @@ -1023,6 +1027,11 @@ static int __cmd_top(struct perf_top *top) =20 if (hits =3D=3D top->samples) ret =3D perf_evlist__poll(top->evlist, 100); + + if (resize) { + perf_top__resize(top); + resize =3D 0; + } } =20 ret =3D 0; --=20 2.11.0