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>
This commit is contained in:
@ -1797,9 +1797,10 @@ int less_main(int argc, char **argv)
|
|||||||
/* Some versions of less can survive w/o controlling tty,
|
/* Some versions of less can survive w/o controlling tty,
|
||||||
* try to do the same. This also allows to specify an alternative
|
* try to do the same. This also allows to specify an alternative
|
||||||
* tty via "less 1<>TTY".
|
* tty via "less 1<>TTY".
|
||||||
* We don't try to use STDOUT_FILENO directly,
|
*
|
||||||
|
* We prefer not to use STDOUT_FILENO directly,
|
||||||
* since we want to set this fd to non-blocking mode,
|
* since we want to set this fd to non-blocking mode,
|
||||||
* and not bother with restoring it on exit.
|
* and not interfere with other processes which share stdout with us.
|
||||||
*/
|
*/
|
||||||
tty_name = xmalloc_ttyname(STDOUT_FILENO);
|
tty_name = xmalloc_ttyname(STDOUT_FILENO);
|
||||||
if (tty_name) {
|
if (tty_name) {
|
||||||
@ -1811,8 +1812,15 @@ int less_main(int argc, char **argv)
|
|||||||
/* Try controlling tty */
|
/* Try controlling tty */
|
||||||
try_ctty:
|
try_ctty:
|
||||||
tty_fd = open(CURRENT_TTY, O_RDONLY);
|
tty_fd = open(CURRENT_TTY, O_RDONLY);
|
||||||
if (tty_fd < 0)
|
if (tty_fd < 0) {
|
||||||
return bb_cat(argv);
|
/*
|
||||||
|
* If all else fails, less 481 uses stdout. Mimic that.
|
||||||
|
* Testcase where usually both ttyname(STDOUT_FILENO)
|
||||||
|
* and open(CURRENT_TTY) fail:
|
||||||
|
* su -s /bin/sh -c 'busybox less FILE' - nobody
|
||||||
|
*/
|
||||||
|
tty_fd = STDOUT_FILENO;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ndelay_on(tty_fd);
|
ndelay_on(tty_fd);
|
||||||
kbd_fd = tty_fd; /* save in a global */
|
kbd_fd = tty_fd; /* save in a global */
|
||||||
|
Reference in New Issue
Block a user