ps: conditionally enable -T on non-DESKTOP build too

function                                             old     new   delta
ps_main                                              253     274     +21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2009-09-21 23:58:43 +02:00
parent 69b1cef921
commit d75295c80b
2 changed files with 28 additions and 28 deletions

View File

@ -479,7 +479,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv)
// Select which columns to display // Select which columns to display
/* We allow (and ignore) most of the above. FIXME */ /* We allow (and ignore) most of the above. FIXME */
opt_complementary = "o::"; opt_complementary = "o::";
opt = getopt32(argv, "Zo:aAdefl" IF_FEATURE_SHOW_THREADS("T"), &opt_o); opt = getopt32(argv, "Zo:aAdefl"IF_FEATURE_SHOW_THREADS("T"), &opt_o);
if (opt_o) { if (opt_o) {
do { do {
parse_o(llist_pop(&opt_o)); parse_o(llist_pop(&opt_o));
@ -528,56 +528,56 @@ int ps_main(int argc UNUSED_PARAM, char **argv)
int ps_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int ps_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{ {
procps_status_t *p = NULL; procps_status_t *p;
int len; int len;
IF_NOT_SELINUX(const) int use_selinux = 0; int psscan_flags = PSSCAN_PID | PSSCAN_UIDGID
IF_SELINUX(int i;) | PSSCAN_STATE | PSSCAN_VSZ | PSSCAN_COMM;
#if !ENABLE_FEATURE_PS_WIDE #if !ENABLE_FEATURE_PS_WIDE
enum { terminal_width = 79 }; enum { terminal_width = 79 };
#else #else
unsigned terminal_width; unsigned terminal_width;
int w_count = 0;
#endif #endif
#if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX #if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX
#if ENABLE_FEATURE_PS_WIDE int opts;
# if ENABLE_FEATURE_PS_WIDE
int w_count = 0;
opt_complementary = "-:ww"; opt_complementary = "-:ww";
IF_SELINUX(i =) getopt32(argv, IF_SELINUX("Z") "w", &w_count); opts = getopt32(argv, IF_SELINUX("Z")IF_FEATURE_SHOW_THREADS("T")"w", &w_count);
/* if w is given once, GNU ps sets the width to 132, /* if w is given once, GNU ps sets the width to 132,
* if w is given more than once, it is "unlimited" * if w is given more than once, it is "unlimited"
*/ */
if (w_count) { if (w_count) {
terminal_width = (w_count==1) ? 132 : MAX_WIDTH; terminal_width = (w_count == 1) ? 132 : MAX_WIDTH;
} else { } else {
get_terminal_width_height(0, &terminal_width, NULL); get_terminal_width_height(0, &terminal_width, NULL);
/* Go one less... */ /* Go one less... */
if (--terminal_width > MAX_WIDTH) if (--terminal_width > MAX_WIDTH)
terminal_width = MAX_WIDTH; terminal_width = MAX_WIDTH;
} }
#else /* only ENABLE_SELINUX */ # else /* only ENABLE_SELINUX */
i = getopt32(argv, "Z"); opts = getopt32(argv, "Z"IF_FEATURE_SHOW_THREADS("T"));
#endif # endif
#if ENABLE_SELINUX # if ENABLE_SELINUX
if ((i & 1) && is_selinux_enabled()) if ((opts & 1) && is_selinux_enabled())
use_selinux = PSSCAN_CONTEXT; psscan_flags = PSSCAN_PID | PSSCAN_CONTEXT
#endif | 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 */ #endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */
if (use_selinux) if (psscan_flags & PSSCAN_CONTEXT)
puts(" PID CONTEXT STAT COMMAND"); puts(" PID CONTEXT STAT COMMAND");
else else
puts(" PID USER VSZ STAT COMMAND"); puts(" PID USER VSZ STAT COMMAND");
while ((p = procps_scan(p, 0 p = NULL;
| PSSCAN_PID while ((p = procps_scan(p, psscan_flags)) != NULL) {
| PSSCAN_UIDGID
| PSSCAN_STATE
| PSSCAN_VSZ
| PSSCAN_COMM
| use_selinux
)) != NULL) {
#if ENABLE_SELINUX #if ENABLE_SELINUX
if (use_selinux) { if (psscan_flags & PSSCAN_CONTEXT) {
len = printf("%5u %-32.32s %s ", len = printf("%5u %-32.32s %s ",
p->pid, p->pid,
p->context ? p->context : "unknown", p->context ? p->context : "unknown",

View File

@ -895,7 +895,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
int lines_rem; int lines_rem;
unsigned interval; unsigned interval;
char *str_interval, *str_iterations; char *str_interval, *str_iterations;
IF_NOT_FEATURE_TOPMEM(const) unsigned scan_mask = TOP_MASK; unsigned scan_mask = TOP_MASK;
#if ENABLE_FEATURE_USE_TERMIOS #if ENABLE_FEATURE_USE_TERMIOS
struct termios new_settings; struct termios new_settings;
struct pollfd pfd[1]; struct pollfd pfd[1];
@ -1080,13 +1080,13 @@ int top_main(int argc UNUSED_PARAM, char **argv)
sort_function[2] = time_sort; sort_function[2] = time_sort;
# endif # endif
} }
#if ENABLE_FEATURE_SHOW_THREADS # if ENABLE_FEATURE_SHOW_THREADS
if (c == 'h' if (c == 'h'
IF_FEATURE_TOPMEM(&& scan_mask != TOPMEM_MASK) IF_FEATURE_TOPMEM(&& scan_mask != TOPMEM_MASK)
) { ) {
scan_mask ^= PSSCAN_TASKS; scan_mask ^= PSSCAN_TASKS;
} }
#endif # endif
# if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE # if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
if (c == 'p') { if (c == 'p') {
IF_FEATURE_TOPMEM(scan_mask = TOP_MASK;) IF_FEATURE_TOPMEM(scan_mask = TOP_MASK;)