diff options
| -rw-r--r-- | procps/ps.c | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/procps/ps.c b/procps/ps.c index 4a917282b..97e239b07 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
| @@ -13,31 +13,19 @@ int ps_main(int argc, char **argv) | |||
| 13 | { | 13 | { |
| 14 | procps_status_t * p; | 14 | procps_status_t * p; |
| 15 | int i, len; | 15 | int i, len; |
| 16 | 16 | SKIP_SELINUX(const) int use_selinux = 0; | |
| 17 | #if ENABLE_SELINUX | 17 | USE_SELINUX(security_context_t sid = NULL;) |
| 18 | int use_selinux = 0; | 18 | #if !ENABLE_FEATURE_PS_WIDE |
| 19 | security_context_t sid = NULL; | 19 | enum { terminal_width = 79 }; |
| 20 | #endif | 20 | #else |
| 21 | |||
| 22 | #if ENABLE_FEATURE_PS_WIDE | ||
| 23 | int terminal_width; | 21 | int terminal_width; |
| 24 | int w_count = 0; | 22 | int w_count = 0; |
| 25 | |||
| 26 | opt_complementary = "-:ww"; | ||
| 27 | #else | ||
| 28 | # define terminal_width 79 | ||
| 29 | #endif | 23 | #endif |
| 30 | 24 | ||
| 31 | #if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX | 25 | #if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX |
| 32 | /* handle arguments */ | ||
| 33 | #if ENABLE_FEATURE_PS_WIDE && ENABLE_SELINUX | ||
| 34 | i = getopt32(argc, argv, "wc", &w_count); | ||
| 35 | #elif ENABLE_FEATURE_PS_WIDE && !ENABLE_SELINUX | ||
| 36 | getopt32(argc, argv, "w", &w_count); | ||
| 37 | #else /* !ENABLE_FEATURE_PS_WIDE && ENABLE_SELINUX */ | ||
| 38 | i = getopt32(argc, argv, "c"); | ||
| 39 | #endif | ||
| 40 | #if ENABLE_FEATURE_PS_WIDE | 26 | #if ENABLE_FEATURE_PS_WIDE |
| 27 | opt_complementary = "-:ww"; | ||
| 28 | USE_SELINUX(i =) getopt32(argc, argv, "w" USE_SELINUX("c"), &w_count); | ||
| 41 | /* if w is given once, GNU ps sets the width to 132, | 29 | /* if w is given once, GNU ps sets the width to 132, |
| 42 | * if w is given more than once, it is "unlimited" | 30 | * if w is given more than once, it is "unlimited" |
| 43 | */ | 31 | */ |
| @@ -48,18 +36,18 @@ int ps_main(int argc, char **argv) | |||
| 48 | /* Go one less... */ | 36 | /* Go one less... */ |
| 49 | terminal_width--; | 37 | terminal_width--; |
| 50 | } | 38 | } |
| 39 | #else /* only ENABLE_SELINUX */ | ||
| 40 | i = getopt32(argc, argv, "c"); | ||
| 51 | #endif | 41 | #endif |
| 52 | #if ENABLE_SELINUX | 42 | #if ENABLE_SELINUX |
| 53 | if ((i & (1+ENABLE_FEATURE_PS_WIDE)) && is_selinux_enabled()) | 43 | if ((i & (1+ENABLE_FEATURE_PS_WIDE)) && is_selinux_enabled()) |
| 54 | use_selinux = 1; | 44 | use_selinux = 1; |
| 55 | #endif | 45 | #endif |
| 56 | #endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */ | 46 | #endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */ |
| 57 | 47 | ||
| 58 | #if ENABLE_SELINUX | ||
| 59 | if (use_selinux) | 48 | if (use_selinux) |
| 60 | puts(" PID Context Stat Command"); | 49 | puts(" PID Context Stat Command"); |
| 61 | else | 50 | else |
| 62 | #endif | ||
| 63 | puts(" PID Uid VmSize Stat Command"); | 51 | puts(" PID Uid VmSize Stat Command"); |
| 64 | 52 | ||
| 65 | while ((p = procps_scan(1)) != 0) { | 53 | while ((p = procps_scan(1)) != 0) { |
| @@ -75,7 +63,7 @@ int ps_main(int argc, char **argv) | |||
| 75 | } | 63 | } |
| 76 | 64 | ||
| 77 | if (sid) { | 65 | if (sid) { |
| 78 | /* I assume sid initilized with NULL */ | 66 | /* I assume sid initialized with NULL */ |
| 79 | len = strlen(sid)+1; | 67 | len = strlen(sid)+1; |
| 80 | safe_strncpy(sbuf, sid, len); | 68 | safe_strncpy(sbuf, sid, len); |
| 81 | freecon(sid); | 69 | freecon(sid); |
| @@ -99,7 +87,7 @@ int ps_main(int argc, char **argv) | |||
| 99 | i = 0; | 87 | i = 0; |
| 100 | if (strlen(namecmd) > (size_t)i) | 88 | if (strlen(namecmd) > (size_t)i) |
| 101 | namecmd[i] = 0; | 89 | namecmd[i] = 0; |
| 102 | printf("%s\n", namecmd); | 90 | puts(namecmd); |
| 103 | } else { | 91 | } else { |
| 104 | namecmd = p->short_cmd; | 92 | namecmd = p->short_cmd; |
| 105 | if (i < 2) | 93 | if (i < 2) |
| @@ -108,7 +96,7 @@ int ps_main(int argc, char **argv) | |||
| 108 | namecmd[i-2] = 0; | 96 | namecmd[i-2] = 0; |
| 109 | printf("[%s]\n", namecmd); | 97 | printf("[%s]\n", namecmd); |
| 110 | } | 98 | } |
| 111 | /* no check needed, but to make valgrind happy.. */ | 99 | /* no check needed, but to make valgrind happy.. */ |
| 112 | if (ENABLE_FEATURE_CLEAN_UP && p->cmd) | 100 | if (ENABLE_FEATURE_CLEAN_UP && p->cmd) |
| 113 | free(p->cmd); | 101 | free(p->cmd); |
| 114 | } | 102 | } |
