If top exits prematurely (missing files in /proc or whatever), make sure we restore the terminal state. Signed-off-by: Mike Frysinger <vapier@xxxxxxxxxx> --- top/top.c | 14 ++++++++++---- 1 files changed, 10 insertions(+), 4 deletions(-) diff --git a/top/top.c b/top/top.c index 41b69a7..7f718dc 100644 --- a/top/top.c +++ b/top/top.c @@ -300,10 +300,8 @@ static const char *tg2 (int x, int y) { /*###### Exit/Interrput routines #######################################*/ - /* - * The real program end */ -static void bye_bye (const char *str) NORETURN; -static void bye_bye (const char *str) { + +static void restore_terminal (void) { if (Ttychanged) { tcsetattr(STDIN_FILENO, TCSAFLUSH, &Tty_original); putp(tg2(0, Screen_rows)); @@ -311,8 +309,15 @@ static void bye_bye (const char *str) { #ifndef RMAN_IGNORED putp(Cap_smam); #endif + Ttychanged = 0; } fflush(stdout); +} + /* + * The real program end */ +static void bye_bye (const char *str) NORETURN; +static void bye_bye (const char *str) { + restore_terminal (); #ifdef ATEOJ_RPTSTD { proc_t *p; @@ -3903,6 +3908,7 @@ static void frame_make (void) { int main (int dont_care_argc, char **argv) { (void)dont_care_argc; atexit(close_stdout); + atexit(restore_terminal); before(*argv); // +-------------+ wins_stage_1(); // top (sic) slice -- 1.7.8.5