[Toybox] [PATCH] Implement ps -O.

enh enh at google.com
Sun Jan 24 22:57:36 PST 2016


On Sun, Jan 24, 2016 at 7:41 PM, Rob Landley <rob at landley.net> wrote:
>
>
> On 01/24/2016 08:19 PM, enh wrote:
>> I should probably expand on the weird -O behavior... The desktop takes
>> it to mean "insert this list of fields after pid and before a short
>> fixed list of other fields" (so that's what this patch does for
>> non-Android), but what I want is a way to move folks off the historical
>> Android abuse of various single-letter flags to add sets of fields that
>> there's no standard flag for. So -c can be replaced by -O psr, for example.
>>
>> One difference is that the desktop doesn't enforce the exclusive or of
>> -O with other flags that would affect the list of fields --- it just
>> ignores -O in case of conflict. But that seems clearly a bug, so I
>> didn't copy it.
>
> The toybox one will happily accept "ps -o pid,pid,pid,pid" if you really
> want to. (Dunno _why_, I'm sure someone will eventually want to for some
> strange reason...)
>
>> On Jan 24, 2016 10:50 AM, "enh" <enh at google.com <mailto:enh at google.com>>
>> wrote:
>>
>>     Also hard-code -W for Android to match traditional behavior,
>
> This change disables the tty width logic completely. Would setting the
> default width when it can't probe terminal size to 99999 instead of 80
> count work here instead?

i notice that the header isn't truncated to the terminal size, which
you presumably consider a bug, but what _might_ be okay is to say "if
the terminal size is less than the space needed for the requested
fields, trust the fields". then we might be able to get away with just
saying that the default Android fields include a wider than desktop
NAME field. but i'm still not sure. folks assume that NAME isn't
truncated. (i've had requests to )

the problem really is that Android defaults to so many fields you
don't get to see much of NAME right now. and that's before people
start adding the extra fields. Android's ps never truncated NAME at
all. i'm hoping long term (when no cares about < N or whatever release
we can switch ps over in) callers will be able to use -o to ask for
exactly what they want. so if they really only want pid and an
untruncated name (which seems fairly common) they can say -o
pid,name:99999 and lose the regular expressions.

(having trailing whitespace in the NAME field caused by truncation
caused a lot of trouble from one attempt to switch over.)

> --- a/toys/posix/ps.c
> +++ b/toys/posix/ps.c
> @@ -966,7 +966,7 @@ static void shared_main(void)
>
>    TT.ticks = sysconf(_SC_CLK_TCK);
>    if (!TT.width) {
> -    TT.width = 80;
> +    TT.width = 99999;
>      TT.height = 25;
>      terminal_size(&TT.width, &TT.height);
>    }

but, yes, this would at least fix the script users.

> I'm hoping that in future Android grows a userbase plugging their phone
> into a USB hub with hdmi adapter, mouse, and keyboard (or chromecasting
> to their TV with bluetooth keyboard and mouse) that can actually pop up
> a terminal window. I'd like android devices to grow into the workstation
> space and organically displace PC hardware. Your suggested change works
> against that goal, when you _do_ have a terminal size, it's good to use
> it...
>
> (I can also make sure it's specifically checking for a terminal on
> stdout, so "ps | thing" also forces -w output. The downside is that
> makes "ps | less" force -w too...)

ps | thing is pretty much the default case in Android, not least
because historically ps couldn't really do anything fancy for itself.

ugh... testing i just realized that toybox will truncate the user
field rather than either auto-size it or just misalign those lines.

> Rob
> _______________________________________________
> Toybox mailing list
> Toybox at lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net



-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.

 1453705056.0


More information about the Toybox mailing list