diff options
-rw-r--r-- | include/libbb.h | 7 | ||||
-rw-r--r-- | libbb/procps.c | 9 | ||||
-rw-r--r-- | procps/ps.c | 23 |
3 files changed, 19 insertions, 20 deletions
diff --git a/include/libbb.h b/include/libbb.h index 5d2b4c8..2cac7e6 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1545,13 +1545,6 @@ enum { PSSCAN_NICE = (1 << 20) * ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS, PSSCAN_RUIDGID = (1 << 21) * ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS, PSSCAN_TASKS = (1 << 22) * ENABLE_FEATURE_SHOW_THREADS, - /* These are all retrieved from proc/NN/stat in one go: */ - PSSCAN_STAT = PSSCAN_PPID | PSSCAN_PGID | PSSCAN_SID - /**/ | PSSCAN_COMM | PSSCAN_STATE - /**/ | PSSCAN_VSZ | PSSCAN_RSS - /**/ | PSSCAN_STIME | PSSCAN_UTIME | PSSCAN_START_TIME - /**/ | PSSCAN_TTY | PSSCAN_NICE - /**/ | PSSCAN_CPU }; //procps_status_t* alloc_procps_scan(void) FAST_FUNC; void free_procps_scan(procps_status_t* sp) FAST_FUNC; diff --git a/libbb/procps.c b/libbb/procps.c index 5833a1f..9207e92 100644 --- a/libbb/procps.c +++ b/libbb/procps.c @@ -357,7 +357,14 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) sp->gid = sb.st_gid; } - if (flags & PSSCAN_STAT) { + /* These are all retrieved from proc/NN/stat in one go: */ + if (flags & (PSSCAN_PPID | PSSCAN_PGID | PSSCAN_SID + | PSSCAN_COMM | PSSCAN_STATE + | PSSCAN_VSZ | PSSCAN_RSS + | PSSCAN_STIME | PSSCAN_UTIME | PSSCAN_START_TIME + | PSSCAN_TTY | PSSCAN_NICE + | PSSCAN_CPU) + ) { char *cp, *comm1; int tty; #if !ENABLE_FEATURE_FAST_TOP diff --git a/procps/ps.c b/procps/ps.c index 279f25e..7537118 100644 --- a/procps/ps.c +++ b/procps/ps.c @@ -87,13 +87,6 @@ enum { MAX_WIDTH = 2*1024 }; * TIME The cumulative execution time for the process * CMD The command name; the full command line is shown with -f */ -#if ENABLE_SELINUX -# define SELINUX_O_PREFIX "label," -# define DEFAULT_O_STR (SELINUX_O_PREFIX "pid,user" IF_FEATURE_PS_TIME(",time") ",args") -#else -# define DEFAULT_O_STR ("pid,user" IF_FEATURE_PS_TIME(",time") ",args") -#endif - typedef struct { uint16_t width; char name6[6]; @@ -113,7 +106,6 @@ struct globals { unsigned kernel_HZ; unsigned long long seconds_since_boot; #endif - char default_o[sizeof(DEFAULT_O_STR)]; } FIX_ALIASING; #define G (*(struct globals*)&bb_common_bufsiz1) #define out (G.out ) @@ -124,7 +116,6 @@ struct globals { #define terminal_width (G.terminal_width ) #define kernel_HZ (G.kernel_HZ ) #define seconds_since_boot (G.seconds_since_boot) -#define default_o (G.default_o ) #define INIT_G() do { } while (0) #if ENABLE_FEATURE_PS_TIME @@ -250,7 +241,7 @@ static void func_comm(char *buf, int size, const procps_status_t *ps) safe_strncpy(buf, ps->comm, size+1); } -static void func_stat(char *buf, int size, const procps_status_t *ps) +static void func_state(char *buf, int size, const procps_status_t *ps) { safe_strncpy(buf, ps->state, size+1); } @@ -394,7 +385,7 @@ static const ps_out_t out_spec[] = { { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, /* Not mandated, but useful: */ - { 4 , "stat" ,"STAT" ,func_stat ,PSSCAN_STAT }, + { 4 , "stat" ,"STAT" ,func_state ,PSSCAN_STATE }, { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS }, #if ENABLE_SELINUX { 35 , "label" ,"LABEL" ,func_label ,PSSCAN_CONTEXT }, @@ -531,11 +522,19 @@ static void format_process(const procps_status_t *ps) printf("%.*s\n", terminal_width, buffer); } +#if ENABLE_SELINUX +# define SELINUX_O_PREFIX "label," +# define DEFAULT_O_STR (SELINUX_O_PREFIX "pid,user" IF_FEATURE_PS_TIME(",time") ",args") +#else +# define DEFAULT_O_STR ("pid,user" IF_FEATURE_PS_TIME(",time") ",args") +#endif + int ps_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int ps_main(int argc UNUSED_PARAM, char **argv) { procps_status_t *p; llist_t* opt_o = NULL; + char default_o[sizeof(DEFAULT_O_STR)]; int opt; enum { OPT_Z = (1 << 0), @@ -573,7 +572,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv) parse_o(llist_pop(&opt_o)); } while (opt_o); } else { - /* Below: parse_o() needs char*, NOT const char*... */ + /* Below: parse_o() needs char*, NOT const char*, can't give it default_o */ #if ENABLE_SELINUX if (!(opt & OPT_Z) || !is_selinux_enabled()) { /* no -Z or no SELinux: do not show LABEL */ |