diff options
Diffstat (limited to 'procps/ps.c')
-rw-r--r-- | procps/ps.c | 63 |
1 files changed, 24 insertions, 39 deletions
diff --git a/procps/ps.c b/procps/ps.c index 003e8eacd..c6bffc60d 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -27,11 +27,7 @@ static void func_comm(char *buf, int size, const procps_status_t *ps) | |||
27 | 27 | ||
28 | static void func_args(char *buf, int size, const procps_status_t *ps) | 28 | static void func_args(char *buf, int size, const procps_status_t *ps) |
29 | { | 29 | { |
30 | buf[0] = '\0'; | 30 | read_cmdline(buf, size, ps->pid, ps->comm); |
31 | if (ps->cmd) | ||
32 | safe_strncpy(buf, ps->cmd, size+1); | ||
33 | else if (size >= 2) | ||
34 | sprintf(buf, "[%.*s]", size-2, ps->comm); | ||
35 | } | 31 | } |
36 | 32 | ||
37 | static void func_pid(char *buf, int size, const procps_status_t *ps) | 33 | static void func_pid(char *buf, int size, const procps_status_t *ps) |
@@ -112,25 +108,25 @@ typedef struct { | |||
112 | 108 | ||
113 | static const ps_out_t out_spec[] = { | 109 | static const ps_out_t out_spec[] = { |
114 | // Mandated by POSIX: | 110 | // Mandated by POSIX: |
115 | { 8 , "user" ,"USER" ,func_user ,PSSCAN_UIDGID }, | 111 | { 8 , "user" ,"USER" ,func_user ,PSSCAN_UIDGID }, |
116 | { 16 , "comm" ,"COMMAND",func_comm ,PSSCAN_COMM }, | 112 | { 16 , "comm" ,"COMMAND",func_comm ,PSSCAN_COMM }, |
117 | { 256 , "args" ,"COMMAND",func_args ,PSSCAN_CMD|PSSCAN_COMM }, | 113 | { 256 , "args" ,"COMMAND",func_args ,PSSCAN_COMM }, |
118 | { 5 , "pid" ,"PID" ,func_pid ,PSSCAN_PID }, | 114 | { 5 , "pid" ,"PID" ,func_pid ,PSSCAN_PID }, |
119 | { 5 , "ppid" ,"PPID" ,func_ppid ,PSSCAN_PPID }, | 115 | { 5 , "ppid" ,"PPID" ,func_ppid ,PSSCAN_PPID }, |
120 | { 5 , "pgid" ,"PGID" ,func_pgid ,PSSCAN_PGID }, | 116 | { 5 , "pgid" ,"PGID" ,func_pgid ,PSSCAN_PGID }, |
121 | // { sizeof("ELAPSED")-1, "etime" ,"ELAPSED",func_etime ,PSSCAN_ }, | 117 | // { sizeof("ELAPSED")-1, "etime" ,"ELAPSED",func_etime ,PSSCAN_ }, |
122 | // { sizeof("GROUP" )-1, "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID }, | 118 | // { sizeof("GROUP" )-1, "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID }, |
123 | // { sizeof("NI" )-1, "nice" ,"NI" ,func_nice ,PSSCAN_ }, | 119 | // { sizeof("NI" )-1, "nice" ,"NI" ,func_nice ,PSSCAN_ }, |
124 | // { sizeof("%CPU" )-1, "pcpu" ,"%CPU" ,func_pcpu ,PSSCAN_ }, | 120 | // { sizeof("%CPU" )-1, "pcpu" ,"%CPU" ,func_pcpu ,PSSCAN_ }, |
125 | // { sizeof("RGROUP" )-1, "rgroup","RGROUP" ,func_rgroup,PSSCAN_UIDGID }, | 121 | // { sizeof("RGROUP" )-1, "rgroup","RGROUP" ,func_rgroup,PSSCAN_UIDGID }, |
126 | // { sizeof("RUSER" )-1, "ruser" ,"RUSER" ,func_ruser ,PSSCAN_UIDGID }, | 122 | // { sizeof("RUSER" )-1, "ruser" ,"RUSER" ,func_ruser ,PSSCAN_UIDGID }, |
127 | // { sizeof("TIME" )-1, "time" ,"TIME" ,func_time ,PSSCAN_ }, | 123 | // { sizeof("TIME" )-1, "time" ,"TIME" ,func_time ,PSSCAN_ }, |
128 | { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, | 124 | { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, |
129 | { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, | 125 | { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, |
130 | // Not mandated by POSIX, but useful: | 126 | // Not mandated by POSIX, but useful: |
131 | { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS }, | 127 | { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS }, |
132 | #if ENABLE_SELINUX | 128 | #if ENABLE_SELINUX |
133 | { 35 , "label" ,"LABEL" ,func_label ,PSSCAN_CONTEXT }, | 129 | { 35 , "label" ,"LABEL" ,func_label ,PSSCAN_CONTEXT }, |
134 | #endif | 130 | #endif |
135 | }; | 131 | }; |
136 | 132 | ||
@@ -386,10 +382,9 @@ int ps_main(int argc, char **argv) | |||
386 | | PSSCAN_UIDGID | 382 | | PSSCAN_UIDGID |
387 | | PSSCAN_STATE | 383 | | PSSCAN_STATE |
388 | | PSSCAN_VSZ | 384 | | PSSCAN_VSZ |
389 | | PSSCAN_CMD | 385 | | PSSCAN_COMM |
390 | | use_selinux | 386 | | use_selinux |
391 | ))) { | 387 | ))) { |
392 | char *namecmd = p->cmd; | ||
393 | #if ENABLE_SELINUX | 388 | #if ENABLE_SELINUX |
394 | if (use_selinux) { | 389 | if (use_selinux) { |
395 | len = printf("%5u %-32s %s ", | 390 | len = printf("%5u %-32s %s ", |
@@ -408,21 +403,11 @@ int ps_main(int argc, char **argv) | |||
408 | p->pid, user, p->vsz, p->state); | 403 | p->pid, user, p->vsz, p->state); |
409 | } | 404 | } |
410 | 405 | ||
411 | i = terminal_width-len; | 406 | { |
412 | 407 | char sz = terminal_width - len; | |
413 | if (namecmd && namecmd[0]) { | 408 | char buf[sz + 1]; |
414 | if (i < 0) | 409 | read_cmdline(buf, sz, p->pid, p->comm); |
415 | i = 0; | 410 | puts(buf); |
416 | if (strlen(namecmd) > (size_t)i) | ||
417 | namecmd[i] = '\0'; | ||
418 | puts(namecmd); | ||
419 | } else { | ||
420 | namecmd = p->comm; | ||
421 | if (i < 2) | ||
422 | i = 2; | ||
423 | if (strlen(namecmd) > ((size_t)i-2)) | ||
424 | namecmd[i-2] = '\0'; | ||
425 | printf("[%s]\n", namecmd); | ||
426 | } | 411 | } |
427 | } | 412 | } |
428 | if (ENABLE_FEATURE_CLEAN_UP) | 413 | if (ENABLE_FEATURE_CLEAN_UP) |