[Toybox] ps on Android

enh enh at google.com
Wed Jun 8 17:09:37 PDT 2016


folks are starting to notice how broken it is...

i'll probably submit https://android-review.googlesource.com/237370
(shown below) tomorrow and then revert it when we have a better
solution.

>From a0d899ba14f390e3cf0f15fb08de349c7ec43270 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 and truncates. This patch switches us over
to "TNAME", disables the implicit -T, and works around the truncation.

(In addition to the obvious "this is not the way we should do this", it
turns out there's also a bug in the header formatting --- TNAME:99 causes
us to output a very wide header line with lots of trailing whitespace.)

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 def81c5..f2c8922 100644
--- 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";
   sprintf(toybuf, not_o, (toys.optflags & FLAG_T) ? "PID,TID," : "PID,");

   // Init TT.fields. This only uses toybuf if TT.ps.o is NULL
@@ -1213,7 +1213,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


More information about the Toybox mailing list