[Toybox] ps on Android

enh enh at google.com
Thu Jun 9 09:24:09 PDT 2016


i'll submit this (same patch as yesterday, minus the width workaround
since that was fixed properly last night) to reduce the urgency, and
revert when we have a real fix:

>From be7bbced789dbb80daa8fe2707ebe9736a2c0732 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <enh at google.com>
Date: Wed, 8 Jun 2016 17:03:26 -0700
Subject: [PATCH] HACK: restore Android ps behavior.

"NAME" is no longer doing what we want; "TNAME" is what "NAME" used to be,
except that "TNAME" implies -T. This patch switches us over to "TNAME",
disables the implicit -T.

Change-Id: I5553703d3939b24eaf39976162d2f75a591e1ce8
---
 toys/posix/ps.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index 4c66bcd..9402b77 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -1194,7 +1194,7 @@ void ps_main(void)
   else if (toys.optflags&FLAG_l)
     not_o = "F,S,UID,%sPPID,C,PRI,NI,ADDR,SZ,WCHAN,TTY,TIME,CMD";
   else if (CFG_TOYBOX_ON_ANDROID)
-    not_o = "USER,%sPPID,VSIZE,RSS,WCHAN:10,ADDR:10=PC,S,NAME";
+    not_o = "USER,%sPPID,VSIZE,RSS,WCHAN:10,ADDR:10=PC,S,TNAME";
   sprintf(toybuf, not_o, (toys.optflags & FLAG_T) ? "PID,TID," : "PID,");

   // Init TT.fields. This only uses toybuf if TT.ps.o is NULL
@@ -1227,7 +1227,7 @@ void ps_main(void)
   if (!(toys.optflags&(FLAG_k|FLAG_M))) TT.show_process = (void *)show_ps;
   TT.match_process = ps_match_process;
   dt = dirtree_read("/proc",
-    ((toys.optflags&FLAG_T) || (TT.bits&(_PS_TID|_PS_TCNT|_PS_TNAME)))
+    ((toys.optflags&FLAG_T) || (TT.bits&(_PS_TID|_PS_TCNT/*|_PS_TNAME*/)))
       ? get_threads : get_ps);

   if (toys.optflags&(FLAG_k|FLAG_M)) {
-- 
2.8.0.rc3.226.g39d4020

On Thu, Jun 9, 2016 at 8:22 AM, enh <enh at google.com> wrote:
> On Wed, Jun 8, 2016 at 9:06 PM, Rob Landley <rob at landley.net> wrote:
>> On 06/08/2016 07:09 PM, enh wrote:
>>> folks are starting to notice how broken it is...
>>
>> I never quite got a clear idea whether or not I should apply the patch
>> in the last email, and I'd held off because I didn't want to make random
>> changes without being sure what you wanted.
>>
>> Lemme go back and finish that email and send it... And I applied the patch.
>>
>> Two pending issues from last message:
>>
>> 1) Rename TNAME to NAME.
>>
>> 2) Make it not force a thread check.
>
> (testing this morning reminded me that there was a third issue --
> albeit much less urgent -- that i think got lost in the megathread...
> i was going to make VSZ and RSS wider for Android so we don't have
> misaligned columns by default, and iirc you said that should be done
> for everyone.)
>
>> Sub-issue of 1, I'm just gonna hijack "CMD" for what "NAME" used to do.
>> COMMAND is /proc/$$/exe and CMD is short COMMAND (minus path).
>>
>>> i'll probably submit https://android-review.googlesource.com/237370
>>> (shown below) tomorrow and then revert it when we have a better
>>> solution.
>>
>> Let's see...
>>
>>> --- a/toys/posix/ps.c
>>> +++ b/toys/posix/ps.c
>>> @@ -1180,7 +1180,7 @@ void ps_main(void)
>>>    else if (toys.optflags&FLAG_l)
>>>      not_o = "F,S,UID,%sPPID,C,PRI,NI,ADDR,SZ,WCHAN,TTY,TIME,CMD";
>>>    else if (CFG_TOYBOX_ON_ANDROID)
>>> -    not_o = "USER,%sPPID,VSIZE,RSS,WCHAN:10,ADDR:10=PC,S,NAME";
>>> +    not_o = "USER,%sPPID,VSIZE,RSS,WCHAN:10,ADDR:10=PC,S,TNAME:99";
>>
>> No, if NAME is the last field, and left justified, then it should
>> automatically expand (without padding) up to whatever it thinks the
>> right edge of the screen is. If it's not doing that, there's a bug.
>> Let's see, if there's no controlling tty, the setup code in
>> shared_main() should choose a default width of 99999 and all the others
>> (top and iotop care here) should choose 80:
>>
>>   if (!TT.width) {
>>     TT.width = (toys.which->name[1] == 's') ? 99999 : 80;
>>     TT.height = 25;
>>     terminal_size(&TT.width, &TT.height);
>>   }
>>
>> (The -w option overrides this, setting width to 99999 in ps_main()
>> before calling shared_main() so the above if (!TT.width) already has a
>> value and the body gets skipped.)
>>
>> Ah. Blah. Yet more fallout from the "Don't truncate number fields"
>> commit. Sigh. I fixed it, sorry about that.
>>
>> (Also, when I move TNAME to NAME I can change the default to the longer
>> -27 so even if it's in the middle it has more space to work with).
>>
>> Rob
>
>
>
> --
> Elliott Hughes - http://who/enh - http://jessies.org/~enh/
> Android native code/tools questions? Mail me/drop by/add me as a reviewer.



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


More information about the Toybox mailing list