[Toybox] weird ps truncation

enh enh at google.com
Mon Jan 30 14:20:10 PST 2017


On Sat, Jan 28, 2017 at 4:16 PM, Rob Landley <rob at landley.net> wrote:
> On 01/27/2017 06:00 PM, enh wrote:
>> Android has a lot of long usernames. the bluetooth code, for example,
>> runs as "bluetooth", and the camera code as "cameraserver". ideally
>> the USER column would grow to fit (especially when the tty is very
>> wide), but right now it's kind of narrow, doesn't grow, and truncates
>> from left rather than the right:
>
> The -w flag disables this, it doesn't just ignore screen width but
> disables truncation of all fields. (I.E. all strings print at their full
> length.)

(yes, though it can be hard to read because the columns get shifted about.)

> As for changing the default behavior: I already made the numeric fields
> leak. Now it sounds like you want the string values to leak and reclaim
> space, which is a less bounded problem. (The numbers aren't going to
> leak _that_ much, but each string could be wider than the screen.)

no, that wasn't actually what i was thinking about. i was thinking
about sizing each column to contain its widest value. sort of more
like how columnated ls works.

> Hmmm, what does ubuntu do here... "sudo useradd
> thisisaverylongusername", switch to that user and "sha1sum /dev/zero"
> and... Ha! Top switches from string to UID if it won't fit in the field.
>
> And ps... darn it, how do I get non-numeric username out of this sucker
> again? (ps ax, af, al don't. Ah, but "ps ax -O user" does. Why does
> ubuntu have a "dbus activated colord system demon" running as its own
> user? Right...)
>
> Anyway, ps _also_ swaps UID for USER when it won't fit in the field. It
> doesn't truncate, it switches output type.
>
> (I note that we are so far beyond the behavior posix specifies for this
> command the curvature of the earth would prevent us from seeing it even
> with powerful telescopes. Just an FYI. No I'm not poking them about it
> because Jorg.)
>
> So what behavior do you _want_ here: swap in numbers, leak/reclaim, or
> preread all preread all the entries and calculate column values like ls
> does? Or just truncate from left instead of from right?

what you've already checked in, fixing the truncation to be
consistent, gets us back to where we were.

beyond that i'm not sure...

the "+" to show we did truncate seems helpful.

switching from USER to UID seems like a clever special case, .

a quick test suggests that 15 is our current longest username, which
is almost twice the current default width of 8:

4 root
6 system
9 bluetooth
10 loop_radio
12 package_info
14 webview_zygote
15 vehicle_network

>> USER       PID  PPID     VSZ    RSS WCHAN            ADDR S NAME
>> ...
>> raserver   609     1  115152  43496 hread_read   f4c10044 S cameraserver
>> ...
>> luetooth 13631     1   17808   1740 le_timeout 77105ff7e8 S wcnss_filter
>>
>> similarly for LABEL; we've been lucky so far in that all the labels
>> i'd seen happen to be <= 30 characters, but for the first time i've
>> started to see slightly longer ones, so
>> "u:r:priv_app_nxfile:s0:c512,c768", say, gets left-truncated to
>> "r:priv_app_nxfile:s0:c512,c768".
>>
>> my username is very short and my desktop doesn't use selinux, so
>> forgive the crappy example, but afaict the tradition is to truncate
>> from the right, and indicate that truncation has taken place by
>> replacing the last character with '+':
>
> I can do that too.
>
>> ~$ ps -O user:2
>>   PID USER S TTY        TIME COMMAND
>> 18357 e+ S pts/23   00:00:00 -/bin/bash
>> 18422 e+ R pts/23   00:00:00 ps -O user:2
>>
>> ah, actually it's weirder than that...
>>
>> $ adb shell ps -AZ | grep too
>> u:r:bluetooth:s0               bluetoot 13320 13015 2245220  58420
>> SyS_epoll_ 6fe4ab06b0 S com.android.bluetooth
>> u:r:wcnss_filter:s0            bluetoot 13631     1   17808   1740
>> poll_sched 77105ff7e8 S wcnss_filter
>> $ adb shell -t ps -AZ | grep too
>> u:r:bluetooth:s0               luetooth 13320 13015 2245220  58420
>> epoll_wait 6fe4ab06b0 S com.android.bluetooth
>> u:r:wcnss_filter:s0            luetooth 13631     1   17808   1740
>> le_timeout 77105ff7e8 S wcnss_filter
>> $
>>
>> if we're writing to a tty ps calls draw_trim but if not, calls printf
>> directly. so in one case we truncate from the correct side (but don't
>> mark the truncation with '+') and in the other we truncate from the
>> wrong side (and also don't mark the truncation).
>
> I.E. this is a bug introduced during the switch to draw_trim. Although
> the "+" for last character thing is new.
>
>> (/me wishes Unix weren't still so ASCII; the unicode ellipsis '…'
>> would be a nice improvement over '+'.)
>
> draw_trim exists to make unicode work; user-supplied strings can be full
> of it and that includes filenames, usernames, etc. I can do elipsis in
> tty mode if you'd like. (Implementing's easy, figuring out the right
> thing to do is hard.)
>
> Right now it sounds like left justifying the string and doing the + is
> the behavior you want, but let me know if you prefer one of the other
> ones...

doing the "+" is at least an obvious signal that something's going on
here. i'm surprised no one's noticed before now that "bluetooth" gets
truncated. actually, here's the list of usernames that get truncated
on a Pixel:

9 bluetooth
9 sdcard_rw
10 loop_radio
12 package_info
11 sdcard_pics
9 sdcard_av
10 sdcard_all
12 shared_relro
11 audioserver
12 metrics_coll
9 debuggerd
10 mediacodec
12 cameraserver
10 dns_tether
14 webview_zygote
15 vehicle_network
11 media_audio
11 media_video
11 media_image
10 tombstoned
9 media_obb
12 net_bt_admin
9 net_admin
12 net_bw_stats
11 net_bw_acct
9 everybody
9 u0_a10000

(that last one is the start of a block of generated usernames of
length 9, corresponding to installed apps.)

maybe Android should just default to 12?

> Rob



-- 
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