Skip to content

Commit 29b4f5f

Browse files
rantalaacmel
authored andcommitted
perf top: Fix stdio interface input handling with glibc 2.28+
Since glibc 2.28 when running 'perf top --stdio', input handling no longer works, but hitting any key always just prints the "Mapped keys" help text. To fix it, call clearerr() in the display_thread() loop to clear any EOF sticky errors, as instructed in the glibc NEWS file (https://sourceware.org/git/?p=glibc.git;a=blob;f=NEWS): * All stdio functions now treat end-of-file as a sticky condition. If you read from a file until EOF, and then the file is enlarged by another process, you must call clearerr or another function with the same effect (e.g. fseek, rewind) before you can read the additional data. This corrects a longstanding C99 conformance bug. It is most likely to affect programs that use stdio to read interactive input from a terminal. (Bug torvalds#1190.) Signed-off-by: Tommi Rantala <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent cfd3bc7 commit 29b4f5f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tools/perf/builtin-top.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,9 @@ static void *display_thread(void *arg)
684684
delay_msecs = top->delay_secs * MSEC_PER_SEC;
685685
set_term_quiet_input(&save);
686686
/* trash return*/
687-
getc(stdin);
687+
clearerr(stdin);
688+
if (poll(&stdin_poll, 1, 0) > 0)
689+
getc(stdin);
688690

689691
while (!done) {
690692
perf_top__print_sym_table(top);

0 commit comments

Comments
 (0)