aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-09-13 20:53:38 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-09-13 20:53:38 +0200
commit3c0e579a06c3f1d428d3642fc46beb4b635e5e6d (patch)
tree29e25faaa95b7cbe9b2998e94ed34d0daa71159b
parent20a3262cd756aadf8771969a4764cd3c571f0a3e (diff)
downloadbusybox-w32-3c0e579a06c3f1d428d3642fc46beb4b635e5e6d.tar.gz
busybox-w32-3c0e579a06c3f1d428d3642fc46beb4b635e5e6d.tar.bz2
busybox-w32-3c0e579a06c3f1d428d3642fc46beb4b635e5e6d.zip
less: fall back to using fd #1 for keyboard reading. Closes 9231
function old new delta less_main 2535 2540 +5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/less.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/miscutils/less.c b/miscutils/less.c
index d1d4a71be..877ab6ef2 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -1797,9 +1797,10 @@ int less_main(int argc, char **argv)
1797 /* Some versions of less can survive w/o controlling tty, 1797 /* Some versions of less can survive w/o controlling tty,
1798 * try to do the same. This also allows to specify an alternative 1798 * try to do the same. This also allows to specify an alternative
1799 * tty via "less 1<>TTY". 1799 * tty via "less 1<>TTY".
1800 * We don't try to use STDOUT_FILENO directly, 1800 *
1801 * We prefer not to use STDOUT_FILENO directly,
1801 * since we want to set this fd to non-blocking mode, 1802 * since we want to set this fd to non-blocking mode,
1802 * and not bother with restoring it on exit. 1803 * and not interfere with other processes which share stdout with us.
1803 */ 1804 */
1804 tty_name = xmalloc_ttyname(STDOUT_FILENO); 1805 tty_name = xmalloc_ttyname(STDOUT_FILENO);
1805 if (tty_name) { 1806 if (tty_name) {
@@ -1811,8 +1812,15 @@ int less_main(int argc, char **argv)
1811 /* Try controlling tty */ 1812 /* Try controlling tty */
1812 try_ctty: 1813 try_ctty:
1813 tty_fd = open(CURRENT_TTY, O_RDONLY); 1814 tty_fd = open(CURRENT_TTY, O_RDONLY);
1814 if (tty_fd < 0) 1815 if (tty_fd < 0) {
1815 return bb_cat(argv); 1816 /*
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;
1823 }
1816 } 1824 }
1817 ndelay_on(tty_fd); 1825 ndelay_on(tty_fd);
1818 kbd_fd = tty_fd; /* save in a global */ 1826 kbd_fd = tty_fd; /* save in a global */