diff options
-rw-r--r-- | miscutils/less.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index 877ab6ef2..61acfdcb5 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -169,6 +169,7 @@ enum { pattern_valid = 0 }; | |||
169 | struct globals { | 169 | struct globals { |
170 | int cur_fline; /* signed */ | 170 | int cur_fline; /* signed */ |
171 | int kbd_fd; /* fd to get input from */ | 171 | int kbd_fd; /* fd to get input from */ |
172 | int kbd_fd_orig_flags; | ||
172 | int less_gets_pos; | 173 | int less_gets_pos; |
173 | /* last position in last line, taking into account tabs */ | 174 | /* last position in last line, taking into account tabs */ |
174 | size_t last_line_pos; | 175 | size_t last_line_pos; |
@@ -304,6 +305,8 @@ static void print_statusline(const char *str) | |||
304 | static void less_exit(int code) | 305 | static void less_exit(int code) |
305 | { | 306 | { |
306 | set_tty_cooked(); | 307 | set_tty_cooked(); |
308 | if (!(G.kbd_fd_orig_flags & O_NONBLOCK)) | ||
309 | ndelay_off(kbd_fd); | ||
307 | clear_line(); | 310 | clear_line(); |
308 | if (code < 0) | 311 | if (code < 0) |
309 | kill_myself_with_sig(- code); /* does not return */ | 312 | kill_myself_with_sig(- code); /* does not return */ |
@@ -1813,16 +1816,11 @@ int less_main(int argc, char **argv) | |||
1813 | try_ctty: | 1816 | try_ctty: |
1814 | tty_fd = open(CURRENT_TTY, O_RDONLY); | 1817 | tty_fd = open(CURRENT_TTY, O_RDONLY); |
1815 | if (tty_fd < 0) { | 1818 | if (tty_fd < 0) { |
1816 | /* | 1819 | /* If all else fails, less 481 uses stdout. Mimic that */ |
1817 | * If all else fails, less 481 uses stdout. Mimic that. | ||
1818 | * Testcase where usually both ttyname(STDOUT_FILENO) | ||
1819 | * and open(CURRENT_TTY) fail: | ||
1820 | * su -s /bin/sh -c 'busybox less FILE' - nobody | ||
1821 | */ | ||
1822 | tty_fd = STDOUT_FILENO; | 1820 | tty_fd = STDOUT_FILENO; |
1823 | } | 1821 | } |
1824 | } | 1822 | } |
1825 | ndelay_on(tty_fd); | 1823 | G.kbd_fd_orig_flags = ndelay_on(tty_fd); |
1826 | kbd_fd = tty_fd; /* save in a global */ | 1824 | kbd_fd = tty_fd; /* save in a global */ |
1827 | 1825 | ||
1828 | tcgetattr(kbd_fd, &term_orig); | 1826 | tcgetattr(kbd_fd, &term_orig); |