File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -1797,9 +1797,10 @@ int less_main(int argc, char **argv)
17971797 /* Some versions of less can survive w/o controlling tty,
17981798 * try to do the same. This also allows to specify an alternative
17991799 * 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,
18011802 * 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 .
18031804 */
18041805 tty_name = xmalloc_ttyname (STDOUT_FILENO );
18051806 if (tty_name ) {
@@ -1811,8 +1812,15 @@ int less_main(int argc, char **argv)
18111812 /* Try controlling tty */
18121813 try_ctty :
18131814 tty_fd = open (CURRENT_TTY , O_RDONLY );
1814- if (tty_fd < 0 )
1815- return bb_cat (argv );
1815+ if (tty_fd < 0 ) {
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+ }
18161824 }
18171825 ndelay_on (tty_fd );
18181826 kbd_fd = tty_fd ; /* save in a global */
You can’t perform that action at this time.
0 commit comments