[Toybox] [PATCH] Implement ps -O.
enh
enh at google.com
Sun Jan 24 10:50:22 PST 2016
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 --------------
A non-text attachment was scrubbed...
Name: 0001-Implement-ps-O.patch
Type: text/x-patch
Size: 3232 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20160124/e17aeece/attachment.bin>
More information about the Toybox
mailing list