diff options
Diffstat (limited to 'procps/ps.c')
-rw-r--r-- | procps/ps.c | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/procps/ps.c b/procps/ps.c index 0c9b71e09..5128c3d59 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -109,7 +109,7 @@ static const ps_out_t out_spec[] = { | |||
109 | // { sizeof("RGROUP" )-1, "rgroup","RGROUP" ,func_rgroup,PSSCAN_UIDGID }, | 109 | // { sizeof("RGROUP" )-1, "rgroup","RGROUP" ,func_rgroup,PSSCAN_UIDGID }, |
110 | // { sizeof("RUSER" )-1, "ruser" ,"RUSER" ,func_ruser ,PSSCAN_UIDGID }, | 110 | // { sizeof("RUSER" )-1, "ruser" ,"RUSER" ,func_ruser ,PSSCAN_UIDGID }, |
111 | // { sizeof("TIME" )-1, "time" ,"TIME" ,func_time ,PSSCAN_ }, | 111 | // { sizeof("TIME" )-1, "time" ,"TIME" ,func_time ,PSSCAN_ }, |
112 | { sizeof("TT" )-1, "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, | 112 | { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, |
113 | { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, | 113 | { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, |
114 | // Not mandated by POSIX, but useful: | 114 | // Not mandated by POSIX, but useful: |
115 | { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS }, | 115 | { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS }, |
@@ -117,13 +117,25 @@ static const ps_out_t out_spec[] = { | |||
117 | 117 | ||
118 | #define VEC_SIZE(v) ( sizeof(v) / sizeof((v)[0]) ) | 118 | #define VEC_SIZE(v) ( sizeof(v) / sizeof((v)[0]) ) |
119 | 119 | ||
120 | static ps_out_t* out; | 120 | #define DEFAULT_O_STR "pid,user" /* TODO: ,vsz,stat */ ",args" |
121 | static int out_cnt; | ||
122 | static int print_header; | ||
123 | static int ps_flags; | ||
124 | static char *buffer; | ||
125 | static unsigned terminal_width; | ||
126 | 121 | ||
122 | struct globals { | ||
123 | ps_out_t* out; | ||
124 | int out_cnt; | ||
125 | int print_header; | ||
126 | int need_flags; | ||
127 | char *buffer; | ||
128 | unsigned terminal_width; | ||
129 | char default_o[sizeof(DEFAULT_O_STR)]; | ||
130 | }; | ||
131 | #define G (*(struct globals*)&bb_common_bufsiz1) | ||
132 | #define out (G.out ) | ||
133 | #define out_cnt (G.out_cnt ) | ||
134 | #define print_header (G.print_header ) | ||
135 | #define need_flags (G.need_flags ) | ||
136 | #define buffer (G.buffer ) | ||
137 | #define terminal_width (G.terminal_width) | ||
138 | #define default_o (G.default_o ) | ||
127 | 139 | ||
128 | static ps_out_t* new_out_t(void) | 140 | static ps_out_t* new_out_t(void) |
129 | { | 141 | { |
@@ -186,7 +198,7 @@ static void post_process(void) | |||
186 | int i; | 198 | int i; |
187 | int width = 0; | 199 | int width = 0; |
188 | for (i = 0; i < out_cnt; i++) { | 200 | for (i = 0; i < out_cnt; i++) { |
189 | ps_flags |= out[i].ps_flags; | 201 | need_flags |= out[i].ps_flags; |
190 | if (out[i].header[0]) { | 202 | if (out[i].header[0]) { |
191 | print_header = 1; | 203 | print_header = 1; |
192 | } | 204 | } |
@@ -241,15 +253,15 @@ static void format_process(const procps_status_t *ps) | |||
241 | printf("%.*s\n", terminal_width, buffer); | 253 | printf("%.*s\n", terminal_width, buffer); |
242 | } | 254 | } |
243 | 255 | ||
244 | /* Cannot be const: parse_o() will choke */ | ||
245 | static char default_o[] = "pid,user" /* TODO: ,vsz,stat */ ",args"; | ||
246 | |||
247 | int ps_main(int argc, char **argv); | 256 | int ps_main(int argc, char **argv); |
248 | int ps_main(int argc, char **argv) | 257 | int ps_main(int argc, char **argv) |
249 | { | 258 | { |
250 | procps_status_t *p; | 259 | procps_status_t *p; |
251 | llist_t* opt_o = NULL; | 260 | llist_t* opt_o = NULL; |
252 | 261 | ||
262 | /* Cannot be const: parse_o() will choke */ | ||
263 | strcpy(default_o, DEFAULT_O_STR); | ||
264 | |||
253 | // POSIX: | 265 | // POSIX: |
254 | // -a Write information for all processes associated with terminals | 266 | // -a Write information for all processes associated with terminals |
255 | // Implementations may omit session leaders from this list | 267 | // Implementations may omit session leaders from this list |
@@ -282,7 +294,7 @@ int ps_main(int argc, char **argv) | |||
282 | format_header(); | 294 | format_header(); |
283 | 295 | ||
284 | p = NULL; | 296 | p = NULL; |
285 | while ((p = procps_scan(p, ps_flags))) { | 297 | while ((p = procps_scan(p, need_flags))) { |
286 | format_process(p); | 298 | format_process(p); |
287 | } | 299 | } |
288 | 300 | ||