Using less in environment without controlling tty

Denys Vlasenko vda.linux at googlemail.com
Mon Aug 5 13:44:03 UTC 2013


On Mon, Aug 5, 2013 at 4:35 AM, Harald Becker <ralda at gmx.de> wrote:
>>You were given an example how to give less a ctty.
>
> I do not want to give less a ctty, to be able to display some
> messages on an external tty.

Will giving it a ctty create any problems? I think not.

The point is, you are trying to use a tool (less) in a non-standard way.
No one ever imposed a requirement on pagers to be able
to use one tty for output and input while ctty is absent,
or is on another tty. Therefore, expecting that a pager
will be able to do it is unreasonable. It may, by chance,
able to pull it off, and another pager (or another version
of the same pager) may fail to do so.

An another example would be to expect that e.g. shell
is able to work on a tty with non-standard attributes.
Say, with "stty eol \t" setting.
Can fdisk be made to work in this case? Sure, why not.
It should query terminal attributes, notice the eol
character, and correctly use TAB as line termination
in its line editing routine.
But does it make sense to implement that? No.
The code to do that adds complexity, will bit rot,
and will not be used by vast majority of people.
The answer for such a feature request would be
"stop messing around, run the programs in a way
they are supposed to be used".

>>This is not the only possible way to achieve that.
>>It's not like anyone forces you to use the given example.
>
> The example does not work, or produce to much overhead for this
> usage. A usage which may easily be achieved with one ore two
> lines of code in Busybox less. Code which shall not break other
> usage.
>
>>I still understand nothing.
>>Can you actually show the script instead of explaining it?
>>I fail to understand the explanation ("send" to that program?
>>what that means?...)
>
> I already attached full source of command_buffer program to one
> of my mails.
>
> use it like:
>
> { echo "Any output"
>   ...
>   echo -e "\0377\0376\0020>|less\0"

You can run sedsid in the line above: replace "|less"
with "setsid sh -c 'exec less </dev/ttyFOO >/dev/ttyFOO 2>&1'"

setsid creates a new session and therefore loses ctty (if any),
then it execs sh, sh opens /dev/ttyFOO,
and since sh is a session leader w/o ctty, it becomes its ctty.
Then sh execs less. That's it.

> } 2>&1 | console_buffer
>
> But there are many other use cases of console_buffer, so I do not
> want to change this program.

You don't have to change console_buffer. You need to change
less invocation, as shown above.


> Denys, I do not want to change how less works, I just want to be
> able to give it a tty to display the messages without much
> overhead in an environment without ctty. And all this is possible
> without changing much code in less. So I do not understand, why
> you insist on this ctty?

I am telling you how you can make ANY interactive program to run
on another tty *correctly*. No code hacks are necessary.
Adding code to support this use in *all* programs is just not feasible.

I already added code which make "less 1<>/dev/ttyFOO" work
as you requested. Please try current git.

-- 
vda


More information about the busybox mailing list