Using less in environment without controlling tty

Laurent Bercot ska-dietlibc at
Fri Jul 26 21:08:31 UTC 2013

> Where console_buffer is a little application to buffer console
> messages in a circular memory buffer. Those messages are flushed
> (and never displayed) if the startup code succeeds without
> errors. In case there are errors, console_buffer forks a command
> and pipes all messages from it's buffer to that command. As
> command I tried to use less, but resulted in a display like cat.

 Hi Harald,
 What you need is simply to have a terminal to display your
messages to. You could use the openvt command (included in
busybox) for that:
 say console_buffer forks display_prog if there are errors,
make it fork "openvt display_prog" instead. Since openvt
redirects stdin, stdout and stderr to the terminal you get,
you'll need to pipe the data via another fd. For instance,
making console_buffer's child read its data on fd 3 and using
"openvt sh -c 'exec display_prog <&3'" should do the trick.

> My current (temporary) fix for this is, to patch Busybox to use
> fd #2 (stderr) als kbd_fd (kbd_fd = 2;) then it is possible to
> redirect output of less to any location you like:
>  ... | less 2<>/dev/ttyN

 The problem of this approach is that it bypasses the built-in
tests in less, so if someone on your system uses less on a
non-terminal fd, it will crash and burn ^^


More information about the busybox mailing list