Skip to content

Commit b135e5e

Browse files
olsajiriacmel
authored andcommitted
perf top: Fix window dimensions change handling
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 <jolsa@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Tested-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-ysuzwz77oev1ftgvdscn9bpu@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 93d10af commit b135e5e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

tools/perf/builtin-top.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#include "sane_ctype.h"
7878

7979
static volatile int done;
80+
static volatile int resize;
8081

8182
#define HEADER_LINE_NR 5
8283

@@ -86,10 +87,13 @@ static void perf_top__update_print_entries(struct perf_top *top)
8687
}
8788

8889
static void perf_top__sig_winch(int sig __maybe_unused,
89-
siginfo_t *info __maybe_unused, void *arg)
90+
siginfo_t *info __maybe_unused, void *arg __maybe_unused)
9091
{
91-
struct perf_top *top = arg;
92+
resize = 1;
93+
}
9294

95+
static void perf_top__resize(struct perf_top *top)
96+
{
9397
get_term_dimensions(&top->winsize);
9498
perf_top__update_print_entries(top);
9599
}
@@ -480,7 +484,7 @@ static bool perf_top__handle_keypress(struct perf_top *top, int c)
480484
.sa_sigaction = perf_top__sig_winch,
481485
.sa_flags = SA_SIGINFO,
482486
};
483-
perf_top__sig_winch(SIGWINCH, NULL, top);
487+
perf_top__resize(top);
484488
sigaction(SIGWINCH, &act, NULL);
485489
} else {
486490
signal(SIGWINCH, SIG_DFL);
@@ -1035,6 +1039,11 @@ static int __cmd_top(struct perf_top *top)
10351039

10361040
if (hits == top->samples)
10371041
ret = perf_evlist__poll(top->evlist, 100);
1042+
1043+
if (resize) {
1044+
perf_top__resize(top);
1045+
resize = 0;
1046+
}
10381047
}
10391048

10401049
ret = 0;

0 commit comments

Comments
 (0)