diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-09-13 21:05:48 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-09-13 21:05:48 +0200 |
commit | 7fa799a97d381902ab27556918722a6e2d138b9e (patch) | |
tree | 6caca4a32217c396cd0b78ab994b3ec4f42d96bb | |
parent | 3c0e579a06c3f1d428d3642fc46beb4b635e5e6d (diff) | |
download | busybox-w32-7fa799a97d381902ab27556918722a6e2d138b9e.tar.gz busybox-w32-7fa799a97d381902ab27556918722a6e2d138b9e.tar.bz2 busybox-w32-7fa799a97d381902ab27556918722a6e2d138b9e.zip |
less: switch off nonblock on kbd_fd before exit
This is only necessary if we use stdout fd.
function old new delta
less_exit 32 51 +19
less_main 2540 2543 +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 22/0) Total: 22 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-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); |