diff options
author | Denys Vlasenko | 2010-04-07 18:03:34 +0200 |
---|---|---|
committer | Denys Vlasenko | 2010-04-07 18:03:34 +0200 |
commit | 39601843d70247a4c40f3810157a331fb8a7193b (patch) | |
tree | b18765b285dd5f251e7cf41e71d4e5ff029346b5 | |
parent | 1854bc1aa2081b99490bd60721122d28fc8a6737 (diff) | |
download | busybox-39601843d70247a4c40f3810157a331fb8a7193b.zip busybox-39601843d70247a4c40f3810157a331fb8a7193b.tar.gz |
ps: fix non-DESKTOP option handling code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | procps/ps.c | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/procps/ps.c b/procps/ps.c index 91ebd68..b82c126 100644 --- a/procps/ps.c +++ b/procps/ps.c @@ -539,18 +539,18 @@ int ps_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) { procps_status_t *p; - int len; int psscan_flags = PSSCAN_PID | PSSCAN_UIDGID | PSSCAN_STATE | PSSCAN_VSZ | PSSCAN_COMM; -#if !ENABLE_FEATURE_PS_WIDE - enum { terminal_width = 79 }; -#else - unsigned terminal_width; -#endif - -#if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX - int opts; + unsigned terminal_width IF_NOT_FEATURE_PS_WIDE(= 79); + enum { + OPT_Z = (1 << 0) * ENABLE_SELINUX, + OPT_T = (1 << ENABLE_SELINUX) * ENABLE_FEATURE_SHOW_THREADS, + }; + int opts = 0; + /* If we support any options, parse argv */ +#if ENABLE_SELINUX || ENABLE_FEATURE_SHOW_THREADS || ENABLE_FEATURE_PS_WIDE # if ENABLE_FEATURE_PS_WIDE + /* -w is a bit complicated */ int w_count = 0; opt_complementary = "-:ww"; opts = getopt32(argv, IF_SELINUX("Z")IF_FEATURE_SHOW_THREADS("T")"w", &w_count); @@ -565,27 +565,30 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) if (--terminal_width > MAX_WIDTH) terminal_width = MAX_WIDTH; } -# else /* only ENABLE_SELINUX */ - opts = getopt32(argv, "Z"IF_FEATURE_SHOW_THREADS("T")); +# else + /* -w is not supported, only -Z and/or -T */ + opt_complementary = "-"; + opts = getopt32(argv, IF_SELINUX("Z")IF_FEATURE_SHOW_THREADS("T")); # endif -# if ENABLE_SELINUX - if ((opts & 1) && is_selinux_enabled()) +#endif + +#if ENABLE_SELINUX + if ((opts & OPT_Z) && is_selinux_enabled()) { psscan_flags = PSSCAN_PID | PSSCAN_CONTEXT | PSSCAN_STATE | PSSCAN_COMM; -# endif -# if ENABLE_FEATURE_SHOW_THREADS - if (opts & (1 << ENABLE_SELINUX)) - psscan_flags |= PSSCAN_TASKS; -# endif -#endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */ - - if (psscan_flags & PSSCAN_CONTEXT) puts(" PID CONTEXT STAT COMMAND"); - else + } else +#endif + { puts(" PID USER VSZ STAT COMMAND"); + } + if (opts & OPT_T) { + psscan_flags |= PSSCAN_TASKS; + } p = NULL; while ((p = procps_scan(p, psscan_flags)) != NULL) { + int len; #if ENABLE_SELINUX if (psscan_flags & PSSCAN_CONTEXT) { len = printf("%5u %-32.32s %s ", @@ -621,4 +624,4 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) return EXIT_SUCCESS; } -#endif /* ENABLE_DESKTOP */ +#endif /* !ENABLE_DESKTOP */ |