aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
author"Vladimir N. Oleynik" <dzo@simtreas.ru>2005-10-04 16:48:26 +0000
committer"Vladimir N. Oleynik" <dzo@simtreas.ru>2005-10-04 16:48:26 +0000
commitbe0ed3d0b94489e08cc9280f65075c42ba80bf8c (patch)
treefb291c675efaad4088d51132c4835913ba2a2eb4 /procps
parent6d6a40cc4b77b8d3930dddce228ab3b37e6bf29e (diff)
downloadbusybox-w32-be0ed3d0b94489e08cc9280f65075c42ba80bf8c.tar.gz
busybox-w32-be0ed3d0b94489e08cc9280f65075c42ba80bf8c.tar.bz2
busybox-w32-be0ed3d0b94489e08cc9280f65075c42ba80bf8c.zip
use updated bb_getopt_ulflags() for ps applet
Diffstat (limited to 'procps')
-rw-r--r--procps/ps.c55
1 files changed, 31 insertions, 24 deletions
diff --git a/procps/ps.c b/procps/ps.c
index a610bb218..a0081c839 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -22,42 +22,50 @@
22#include <selinux/selinux.h> /* for is_selinux_enabled() */ 22#include <selinux/selinux.h> /* for is_selinux_enabled() */
23#endif 23#endif
24 24
25#define TERMINAL_WIDTH 80
26
27extern int ps_main(int argc, char **argv) 25extern int ps_main(int argc, char **argv)
28{ 26{
29 procps_status_t * p; 27 procps_status_t * p;
30 int i, len, terminal_width; 28 int i, len;
31#if ENABLE_SELINUX 29#if ENABLE_SELINUX
32 int use_selinux = 0; 30 int use_selinux = 0;
33 security_context_t sid=NULL; 31 security_context_t sid=NULL;
34#endif 32#endif
35 33#if ENABLE_FEATURE_PS_WIDE
36 get_terminal_width_height(0, &terminal_width, NULL); 34 int terminal_width;
35 int w_count = 0;
36#else
37# define terminal_width 80
38#endif
37 39
38#if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX 40#if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX
39 /* handle arguments */ 41 /* handle arguments */
40 /* bb_getopt_ulflags(argc, argv,) would force a leading dash */ 42#if ENABLE_FEATURE_PS_WIDE && ENABLE_SELINUX
41 for (len = 1; len < argc; len++) { 43 bb_opt_complementally="ww";
42 char *c = argv[len]; 44 i = bb_getopt_ulflags(argc, argv, "wc", &w_count);
43 while (*c) { 45#elif ENABLE_FEATURE_PS_WIDE && !ENABLE_SELINUX
44 if (ENABLE_FEATURE_PS_WIDE && *c == 'w') 46 bb_opt_complementally="ww";
45 /* if w is given once, GNU ps sets the width to 132, 47 i = bb_getopt_ulflags(argc, argv, "w", &w_count);
46 * if w is given more than once, it is "unlimited" 48#else /* !ENABLE_FEATURE_PS_WIDE && !ENABLE_SELINUX */
47 */ 49 i = bb_getopt_ulflags(argc, argv, "c");
48 terminal_width =
49 (terminal_width==TERMINAL_WIDTH) ? 132 : INT_MAX;
50#if ENABLE_SELINUX
51 if (*c == 'c' && is_selinux_enabled())
52 use_selinux = 1;
53#endif 50#endif
54 c++; 51#if ENABLE_FEATURE_PS_WIDE
55 } 52 /* if w is given once, GNU ps sets the width to 132,
53 * if w is given more than once, it is "unlimited"
54 */
55 if((i & 1)) {
56 terminal_width = (w_count==1) ? 132 : INT_MAX;
57 } else {
58 get_terminal_width_height(0, &terminal_width, NULL);
59 /* Go one less... */
60 terminal_width--;
56 } 61 }
57#endif 62#endif
63#if ENABLE_SELINUX
64 if ((i & 2) && is_selinux_enabled())
65 use_selinux = 1;
66#endif
67#endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */
58 68
59 /* Go one less... */
60 terminal_width--;
61#if ENABLE_SELINUX 69#if ENABLE_SELINUX
62 if (use_selinux) 70 if (use_selinux)
63 printf(" PID Context Stat Command\n"); 71 printf(" PID Context Stat Command\n");
@@ -68,7 +76,7 @@ extern int ps_main(int argc, char **argv)
68 while ((p = procps_scan(1)) != 0) { 76 while ((p = procps_scan(1)) != 0) {
69 char *namecmd = p->cmd; 77 char *namecmd = p->cmd;
70#if ENABLE_SELINUX 78#if ENABLE_SELINUX
71 if (use_selinux ) 79 if (use_selinux)
72 { 80 {
73 char sbuf[128]; 81 char sbuf[128];
74 len = sizeof(sbuf); 82 len = sizeof(sbuf);
@@ -118,4 +126,3 @@ extern int ps_main(int argc, char **argv)
118 } 126 }
119 return EXIT_SUCCESS; 127 return EXIT_SUCCESS;
120} 128}
121