diff options
-rw-r--r-- | miscutils/less.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index 26983f4..6825e55 100644 --- a/miscutils/less.c +++ b/miscutils/less.c @@ -325,15 +325,18 @@ static void print_statusline(const char *str) } /* Exit the program gracefully */ -static void less_exit(int code) +static void restore_tty(void) { set_tty_cooked(); if (!(G.kbd_fd_orig_flags & O_NONBLOCK)) ndelay_off(kbd_fd); clear_line(); - if (code < 0) - kill_myself_with_sig(- code); /* does not return */ - exit(code); +} + +static void less_exit(void) +{ + restore_tty(); + exit(EXIT_SUCCESS); } #if (ENABLE_FEATURE_LESS_DASHCMD && ENABLE_FEATURE_LESS_LINENUMS) \ @@ -913,7 +916,7 @@ static void buffer_print(void) ) { i = option_mask32 & FLAG_F ? 0 : cur_fline; if (max_fline - i <= max_displayed_line) - less_exit(EXIT_SUCCESS); + less_exit(); } status_print(); } @@ -1146,7 +1149,7 @@ static int64_t getch_nowait(void) goto again; } /* EOF/error (ssh session got killed etc) */ - less_exit(EXIT_SUCCESS); + less_exit(); } set_tty_cooked(); return key64; @@ -1297,7 +1300,7 @@ static void colon_process(void) change_file(-1); break; case 'q': - less_exit(EXIT_SUCCESS); + less_exit(); break; case 'x': change_file(0); @@ -1715,7 +1718,7 @@ static void keypress_process(int keypress) buffer_line(cur_fline); break; case 'q': case 'Q': - less_exit(EXIT_SUCCESS); + less_exit(); break; #if ENABLE_FEATURE_LESS_MARKS case 'm': @@ -1793,7 +1796,8 @@ static void keypress_process(int keypress) static void sig_catcher(int sig) { - less_exit(- sig); + restore_tty(); + kill_myself_with_sig(sig); /* does not return */ } #if ENABLE_FEATURE_LESS_WINCH |