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