<p dir="ltr">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.</p>
<p dir="ltr">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. </p>
<div class="gmail_quote">On Jan 24, 2016 10:50 AM, "enh" <<a href="mailto:enh@google.com">enh@google.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Also hard-code -W for Android to match traditional behavior, and use<br>
NAME rather than CMDLINE by default (again, to match traditional behavior).<br>
---<br>
toys/posix/ps.c | 23 ++++++++++++++++++-----<br>
1 file changed, 18 insertions(+), 5 deletions(-)<br>
<br>
diff --git a/toys/posix/ps.c b/toys/posix/ps.c<br>
index b06be42..8ee2b0f 100644<br>
--- a/toys/posix/ps.c<br>
+++ b/toys/posix/ps.c<br>
@@ -35,7 +35,7 @@<br>
* TODO: iotop: Window size change: respond immediately. Why not padding<br>
* at right edge? (Not adjusting to screen size at all? Header wraps?)<br>
<br>
-USE_PS(NEWTOY(ps,<br>
"k(sort)*P(ppid)*aAdeflno*p(pid)*s*t*u*U*g*G*wZ[!ol][+Ae]",<br>
TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))<br>
+USE_PS(NEWTOY(ps,<br>
"k(sort)*P(ppid)*aAdeflno*O*p(pid)*s*t*u*U*g*G*wZ[!ol][!Oofl][+Ae]",<br>
TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))<br>
// stayroot because iotop needs root to read other process' proc/$$/io<br>
USE_TOP(NEWTOY(top, ">0m" "p*u*d#=3<1n#<1bq",<br>
TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_STAYROOT|TOYFLAG_LOCALE))<br>
USE_IOTOP(NEWTOY(iotop, ">0Aako" "p*u*d#=3<1n#<1bq",<br>
TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_STAYROOT|TOYFLAG_LOCALE))<br>
@@ -76,6 +76,7 @@ config PS<br>
-f Full listing (-o USER:8=UID,PID,PPID,C,STIME,TTY,TIME,CMD)<br>
-l Long listing (-o F,S,UID,PID,PPID,C,PRI,NI,ADDR,SZ,WCHAN,TTY,TIME,CMD)<br>
-o Output the listed FIELDs, each with optional :size and/or =title<br>
+ -O Output the listed FIELDs in addition to the defaults<br>
-Z Include LABEL<br>
<br>
Available -o FIELDs:<br>
@@ -213,6 +214,7 @@ GLOBALS(<br>
struct arg_list *t;<br>
struct arg_list *s;<br>
struct arg_list *p;<br>
+ struct arg_list *O;<br>
struct arg_list *o;<br>
struct arg_list *P;<br>
struct arg_list *k;<br>
@@ -988,7 +990,7 @@ void ps_main(void)<br>
struct dirtree *dt;<br>
int i;<br>
<br>
- if (toys.optflags&FLAG_w) TT.width = 99999;<br>
+ if (CFG_TOYBOX_ON_ANDROID || toys.optflags&FLAG_w) TT.width = 99999;<br>
shared_main();<br>
<br>
// parse command line options other than -o<br>
@@ -1011,7 +1013,19 @@ void ps_main(void)<br>
comma_args(&Z, &TT.fields, "-Z", parse_ko);<br>
}<br>
if (TT.ps.o) comma_args(TT.ps.o, &TT.fields, "bad -o field", parse_ko);<br>
- else {<br>
+ else if (TT.ps.O) {<br>
+ struct arg_list al;<br>
+<br>
+ al.next = 0;<br>
+ al.arg = CFG_TOYBOX_ON_ANDROID ?<br>
+ "USER,PID,PPID,VSIZE,RSS,WCHAN:10,ADDR:10=PC,S" : "PID";<br>
+ comma_args(&al, &TT.fields, 0, parse_ko);<br>
+ comma_args(TT.ps.O, &TT.fields, "bad -O field", parse_ko);<br>
+<br>
+ al.next = 0;<br>
+ al.arg = CFG_TOYBOX_ON_ANDROID ? "NAME" : "TTY,TIME,CMD";<br>
+ comma_args(&al, &TT.fields, 0, parse_ko);<br>
+ } else {<br>
struct arg_list al;<br>
<br>
al.next = 0;<br>
@@ -1020,9 +1034,8 @@ void ps_main(void)<br>
else if (toys.optflags&FLAG_l)<br>
al.arg = "F,S,UID,PID,PPID,C,PRI,NI,ADDR,SZ,WCHAN,TTY,TIME,CMD";<br>
else if (CFG_TOYBOX_ON_ANDROID)<br>
- al.arg = "USER,PID,PPID,VSIZE,RSS,WCHAN:10,ADDR:10=PC,S,CMDLINE";<br>
+ al.arg = "USER,PID,PPID,VSIZE,RSS,WCHAN:10,ADDR:10=PC,S,NAME";<br>
else al.arg = "PID,TTY,TIME,CMD";<br>
-<br>
comma_args(&al, &TT.fields, 0, parse_ko);<br>
}<br>
dlist_terminate(TT.fields);<br>
--<br>
2.7.0.rc3.207.g0ac5344<br>
</blockquote></div>