diff options
Diffstat (limited to 'procps/ps.c')
-rw-r--r-- | procps/ps.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/procps/ps.c b/procps/ps.c index b35b49c04..d86ac6d2f 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -479,7 +479,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv) | |||
479 | // Select which columns to display | 479 | // Select which columns to display |
480 | /* We allow (and ignore) most of the above. FIXME */ | 480 | /* We allow (and ignore) most of the above. FIXME */ |
481 | opt_complementary = "o::"; | 481 | opt_complementary = "o::"; |
482 | opt = getopt32(argv, "Zo:aAdefl" IF_FEATURE_SHOW_THREADS("T"), &opt_o); | 482 | opt = getopt32(argv, "Zo:aAdefl"IF_FEATURE_SHOW_THREADS("T"), &opt_o); |
483 | if (opt_o) { | 483 | if (opt_o) { |
484 | do { | 484 | do { |
485 | parse_o(llist_pop(&opt_o)); | 485 | parse_o(llist_pop(&opt_o)); |
@@ -528,56 +528,56 @@ int ps_main(int argc UNUSED_PARAM, char **argv) | |||
528 | int ps_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 528 | int ps_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
529 | int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | 529 | int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
530 | { | 530 | { |
531 | procps_status_t *p = NULL; | 531 | procps_status_t *p; |
532 | int len; | 532 | int len; |
533 | IF_NOT_SELINUX(const) int use_selinux = 0; | 533 | int psscan_flags = PSSCAN_PID | PSSCAN_UIDGID |
534 | IF_SELINUX(int i;) | 534 | | PSSCAN_STATE | PSSCAN_VSZ | PSSCAN_COMM; |
535 | #if !ENABLE_FEATURE_PS_WIDE | 535 | #if !ENABLE_FEATURE_PS_WIDE |
536 | enum { terminal_width = 79 }; | 536 | enum { terminal_width = 79 }; |
537 | #else | 537 | #else |
538 | unsigned terminal_width; | 538 | unsigned terminal_width; |
539 | int w_count = 0; | ||
540 | #endif | 539 | #endif |
541 | 540 | ||
542 | #if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX | 541 | #if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX |
543 | #if ENABLE_FEATURE_PS_WIDE | 542 | int opts; |
543 | # if ENABLE_FEATURE_PS_WIDE | ||
544 | int w_count = 0; | ||
544 | opt_complementary = "-:ww"; | 545 | opt_complementary = "-:ww"; |
545 | IF_SELINUX(i =) getopt32(argv, IF_SELINUX("Z") "w", &w_count); | 546 | opts = getopt32(argv, IF_SELINUX("Z")IF_FEATURE_SHOW_THREADS("T")"w", &w_count); |
546 | /* if w is given once, GNU ps sets the width to 132, | 547 | /* if w is given once, GNU ps sets the width to 132, |
547 | * if w is given more than once, it is "unlimited" | 548 | * if w is given more than once, it is "unlimited" |
548 | */ | 549 | */ |
549 | if (w_count) { | 550 | if (w_count) { |
550 | terminal_width = (w_count==1) ? 132 : MAX_WIDTH; | 551 | terminal_width = (w_count == 1) ? 132 : MAX_WIDTH; |
551 | } else { | 552 | } else { |
552 | get_terminal_width_height(0, &terminal_width, NULL); | 553 | get_terminal_width_height(0, &terminal_width, NULL); |
553 | /* Go one less... */ | 554 | /* Go one less... */ |
554 | if (--terminal_width > MAX_WIDTH) | 555 | if (--terminal_width > MAX_WIDTH) |
555 | terminal_width = MAX_WIDTH; | 556 | terminal_width = MAX_WIDTH; |
556 | } | 557 | } |
557 | #else /* only ENABLE_SELINUX */ | 558 | # else /* only ENABLE_SELINUX */ |
558 | i = getopt32(argv, "Z"); | 559 | opts = getopt32(argv, "Z"IF_FEATURE_SHOW_THREADS("T")); |
559 | #endif | 560 | # endif |
560 | #if ENABLE_SELINUX | 561 | # if ENABLE_SELINUX |
561 | if ((i & 1) && is_selinux_enabled()) | 562 | if ((opts & 1) && is_selinux_enabled()) |
562 | use_selinux = PSSCAN_CONTEXT; | 563 | psscan_flags = PSSCAN_PID | PSSCAN_CONTEXT |
563 | #endif | 564 | | PSSCAN_STATE | PSSCAN_COMM; |
565 | # endif | ||
566 | # if ENABLE_FEATURE_SHOW_THREADS | ||
567 | if (opts & (1 << ENABLE_SELINUX)) | ||
568 | psscan_flags |= PSSCAN_TASKS; | ||
569 | # endif | ||
564 | #endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */ | 570 | #endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */ |
565 | 571 | ||
566 | if (use_selinux) | 572 | if (psscan_flags & PSSCAN_CONTEXT) |
567 | puts(" PID CONTEXT STAT COMMAND"); | 573 | puts(" PID CONTEXT STAT COMMAND"); |
568 | else | 574 | else |
569 | puts(" PID USER VSZ STAT COMMAND"); | 575 | puts(" PID USER VSZ STAT COMMAND"); |
570 | 576 | ||
571 | while ((p = procps_scan(p, 0 | 577 | p = NULL; |
572 | | PSSCAN_PID | 578 | while ((p = procps_scan(p, psscan_flags)) != NULL) { |
573 | | PSSCAN_UIDGID | ||
574 | | PSSCAN_STATE | ||
575 | | PSSCAN_VSZ | ||
576 | | PSSCAN_COMM | ||
577 | | use_selinux | ||
578 | )) != NULL) { | ||
579 | #if ENABLE_SELINUX | 579 | #if ENABLE_SELINUX |
580 | if (use_selinux) { | 580 | if (psscan_flags & PSSCAN_CONTEXT) { |
581 | len = printf("%5u %-32.32s %s ", | 581 | len = printf("%5u %-32.32s %s ", |
582 | p->pid, | 582 | p->pid, |
583 | p->context ? p->context : "unknown", | 583 | p->context ? p->context : "unknown", |