diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-07-03 22:16:17 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-07-03 22:16:17 +0200 |
commit | fca70a8cce579ce8cc8caf246c22f0c6e6c6e139 (patch) | |
tree | 2c17970b64b12c34624a18cf42b2c39a2cb5329d /procps/ps.c | |
parent | c5d07fba29a477569a96777c9cab73e53b1ddd5c (diff) | |
download | busybox-w32-fca70a8cce579ce8cc8caf246c22f0c6e6c6e139.tar.gz busybox-w32-fca70a8cce579ce8cc8caf246c22f0c6e6c6e139.tar.bz2 busybox-w32-fca70a8cce579ce8cc8caf246c22f0c6e6c6e139.zip |
ps: conditionally support additional -o FIELDs
function old new delta
procps_scan 1409 1642 +233
out_spec 220 300 +80
func_ruser - 36 +36
func_rgroup - 36 +36
func_group 13 49 +36
func_nice - 29 +29
buffer_fill_and_print 179 196 +17
send_tree 355 360 +5
mkfs_vfat_main 1604 1609 +5
display_speed 85 90 +5
scriptreplay_main 194 197 +3
find_out_spec 55 58 +3
changepath 192 195 +3
sha1_process_block64 497 484 -13
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 10/1 up/down: 491/-13) Total: 478 bytes
Signed-off-by: David Krakov <krakov@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'procps/ps.c')
-rw-r--r-- | procps/ps.c | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/procps/ps.c b/procps/ps.c index b9a4aef15..4a6b60bdc 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -32,7 +32,7 @@ enum { MAX_WIDTH = 2*1024 }; | |||
32 | 32 | ||
33 | typedef struct { | 33 | typedef struct { |
34 | uint16_t width; | 34 | uint16_t width; |
35 | char name[6]; | 35 | char name6[6]; |
36 | const char *header; | 36 | const char *header; |
37 | void (*f)(char *buf, int size, const procps_status_t *ps); | 37 | void (*f)(char *buf, int size, const procps_status_t *ps); |
38 | int ps_flags; | 38 | int ps_flags; |
@@ -174,6 +174,11 @@ static void func_user(char *buf, int size, const procps_status_t *ps) | |||
174 | #endif | 174 | #endif |
175 | } | 175 | } |
176 | 176 | ||
177 | static void func_group(char *buf, int size, const procps_status_t *ps) | ||
178 | { | ||
179 | safe_strncpy(buf, get_cached_groupname(ps->gid), size+1); | ||
180 | } | ||
181 | |||
177 | static void func_comm(char *buf, int size, const procps_status_t *ps) | 182 | static void func_comm(char *buf, int size, const procps_status_t *ps) |
178 | { | 183 | { |
179 | safe_strncpy(buf, ps->comm, size+1); | 184 | safe_strncpy(buf, ps->comm, size+1); |
@@ -227,6 +232,26 @@ static void func_tty(char *buf, int size, const procps_status_t *ps) | |||
227 | snprintf(buf, size+1, "%u,%u", ps->tty_major, ps->tty_minor); | 232 | snprintf(buf, size+1, "%u,%u", ps->tty_major, ps->tty_minor); |
228 | } | 233 | } |
229 | 234 | ||
235 | |||
236 | #if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS | ||
237 | |||
238 | static void func_rgroup(char *buf, int size, const procps_status_t *ps) | ||
239 | { | ||
240 | safe_strncpy(buf, get_cached_groupname(ps->rgid), size+1); | ||
241 | } | ||
242 | |||
243 | static void func_ruser(char *buf, int size, const procps_status_t *ps) | ||
244 | { | ||
245 | safe_strncpy(buf, get_cached_username(ps->ruid), size+1); | ||
246 | } | ||
247 | |||
248 | static void func_nice(char *buf, int size, const procps_status_t *ps) | ||
249 | { | ||
250 | sprintf(buf, "%*d", size, ps->niceness); | ||
251 | } | ||
252 | |||
253 | #endif /* FEATURE_PS_ADDITIONAL_COLUMNS */ | ||
254 | |||
230 | #if ENABLE_FEATURE_PS_TIME | 255 | #if ENABLE_FEATURE_PS_TIME |
231 | static void func_etime(char *buf, int size, const procps_status_t *ps) | 256 | static void func_etime(char *buf, int size, const procps_status_t *ps) |
232 | { | 257 | { |
@@ -276,6 +301,7 @@ static void func_pcpu(char *buf, int size, const procps_status_t *ps) | |||
276 | static const ps_out_t out_spec[] = { | 301 | static const ps_out_t out_spec[] = { |
277 | // Mandated by POSIX: | 302 | // Mandated by POSIX: |
278 | { 8 , "user" ,"USER" ,func_user ,PSSCAN_UIDGID }, | 303 | { 8 , "user" ,"USER" ,func_user ,PSSCAN_UIDGID }, |
304 | { 8 , "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID }, | ||
279 | { 16 , "comm" ,"COMMAND",func_comm ,PSSCAN_COMM }, | 305 | { 16 , "comm" ,"COMMAND",func_comm ,PSSCAN_COMM }, |
280 | { 256 , "args" ,"COMMAND",func_args ,PSSCAN_COMM }, | 306 | { 256 , "args" ,"COMMAND",func_args ,PSSCAN_COMM }, |
281 | { 5 , "pid" ,"PID" ,func_pid ,PSSCAN_PID }, | 307 | { 5 , "pid" ,"PID" ,func_pid ,PSSCAN_PID }, |
@@ -284,11 +310,12 @@ static const ps_out_t out_spec[] = { | |||
284 | #if ENABLE_FEATURE_PS_TIME | 310 | #if ENABLE_FEATURE_PS_TIME |
285 | { sizeof("ELAPSED")-1, "etime" ,"ELAPSED",func_etime ,PSSCAN_START_TIME }, | 311 | { sizeof("ELAPSED")-1, "etime" ,"ELAPSED",func_etime ,PSSCAN_START_TIME }, |
286 | #endif | 312 | #endif |
287 | // { sizeof("GROUP" )-1, "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID }, | 313 | #if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS |
288 | // { sizeof("NI" )-1, "nice" ,"NI" ,func_nice ,PSSCAN_ }, | 314 | { 5 , "nice" ,"NI" ,func_nice ,PSSCAN_NICE }, |
289 | // { sizeof("%CPU" )-1, "pcpu" ,"%CPU" ,func_pcpu ,PSSCAN_ }, | 315 | { 8 , "rgroup","RGROUP" ,func_rgroup,PSSCAN_RUIDGID }, |
290 | // { sizeof("RGROUP" )-1, "rgroup","RGROUP" ,func_rgroup,PSSCAN_UIDGID }, | 316 | { 8 , "ruser" ,"RUSER" ,func_ruser ,PSSCAN_RUIDGID }, |
291 | // { sizeof("RUSER" )-1, "ruser" ,"RUSER" ,func_ruser ,PSSCAN_UIDGID }, | 317 | // { 5 , "pcpu" ,"%CPU" ,func_pcpu ,PSSCAN_ }, |
318 | #endif | ||
292 | #if ENABLE_FEATURE_PS_TIME | 319 | #if ENABLE_FEATURE_PS_TIME |
293 | { 6 , "time" ,"TIME" ,func_time ,PSSCAN_STIME | PSSCAN_UTIME }, | 320 | { 6 , "time" ,"TIME" ,func_time ,PSSCAN_STIME | PSSCAN_UTIME }, |
294 | #endif | 321 | #endif |
@@ -311,7 +338,7 @@ static const ps_out_t* find_out_spec(const char *name) | |||
311 | { | 338 | { |
312 | unsigned i; | 339 | unsigned i; |
313 | for (i = 0; i < ARRAY_SIZE(out_spec); i++) { | 340 | for (i = 0; i < ARRAY_SIZE(out_spec); i++) { |
314 | if (!strcmp(name, out_spec[i].name)) | 341 | if (!strncmp(name, out_spec[i].name6, 6)) |
315 | return &out_spec[i]; | 342 | return &out_spec[i]; |
316 | } | 343 | } |
317 | bb_error_msg_and_die("bad -o argument '%s'", name); | 344 | bb_error_msg_and_die("bad -o argument '%s'", name); |