diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2005-10-04 14:31:18 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2005-10-04 14:31:18 +0000 |
commit | 6d6a40cc4b77b8d3930dddce228ab3b37e6bf29e (patch) | |
tree | 64536b70ee179abd59e0c2813309b3dd4ee85e7a | |
parent | 5209e18ba72fa6718fdda7d91788f9b11e352c60 (diff) | |
download | busybox-w32-6d6a40cc4b77b8d3930dddce228ab3b37e6bf29e.tar.gz busybox-w32-6d6a40cc4b77b8d3930dddce228ab3b37e6bf29e.tar.bz2 busybox-w32-6d6a40cc4b77b8d3930dddce228ab3b37e6bf29e.zip |
- add option 'w' to ps (wide output, optional feature defaults to off).
- move to ENABLE_ and use shorter boilerplate.
sizes without selinux-support:
text data bss dec hex filename
356 0 0 356 164 procps/ps.o.with-w
300 0 0 300 12c procps/ps.o.no-w
302 0 0 302 12e procps/ps.o.oorig
-rw-r--r-- | include/usage.h | 10 | ||||
-rw-r--r-- | procps/Config.in | 9 | ||||
-rw-r--r-- | procps/ps.c | 68 |
3 files changed, 48 insertions, 39 deletions
diff --git a/include/usage.h b/include/usage.h index 8428bfd32..fad50efdc 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -2245,17 +2245,12 @@ | |||
2245 | "$ printf \"Val=%d\\n\" 5\n" \ | 2245 | "$ printf \"Val=%d\\n\" 5\n" \ |
2246 | "Val=5\n" | 2246 | "Val=5\n" |
2247 | 2247 | ||
2248 | #if !defined(CONFIG_SELINUX) && !defined(CONFIG_PS_FEATURE_WIDE) | 2248 | #if !defined CONFIG_SELINUX && !ENABLE_FEATURE_PS_WIDE |
2249 | #define USAGE_PS "\n\tThis version of ps accepts no options." | 2249 | #define USAGE_PS "\n\tThis version of ps accepts no options." |
2250 | #else | 2250 | #else |
2251 | #define USAGE_PS "\nOptions:" | 2251 | #define USAGE_PS "\nOptions:" |
2252 | #endif | 2252 | #endif |
2253 | #ifdef CONFIG_SELINUX | 2253 | #if ENABLE_FEATURE_PS_WIDE |
2254 | #define USAGE_NONSELINUX(a) | ||
2255 | #else | ||
2256 | #define USAGE_NONSELINUX(a) a | ||
2257 | #endif | ||
2258 | #ifdef CONFIG_PS_FEATURE_WIDE | ||
2259 | #define USAGE_PS_WIDE(a) a | 2254 | #define USAGE_PS_WIDE(a) a |
2260 | #else | 2255 | #else |
2261 | #define USAGE_PS_WIDE(a) | 2256 | #define USAGE_PS_WIDE(a) |
@@ -2269,7 +2264,6 @@ | |||
2269 | USAGE_SELINUX("\n\t-c\tshow SE Linux context") \ | 2264 | USAGE_SELINUX("\n\t-c\tshow SE Linux context") \ |
2270 | USAGE_PS_WIDE("\n\tw\twide output") | 2265 | USAGE_PS_WIDE("\n\tw\twide output") |
2271 | 2266 | ||
2272 | |||
2273 | #define ps_example_usage \ | 2267 | #define ps_example_usage \ |
2274 | "$ ps\n" \ | 2268 | "$ ps\n" \ |
2275 | " PID Uid Gid State Command\n" \ | 2269 | " PID Uid Gid State Command\n" \ |
diff --git a/procps/Config.in b/procps/Config.in index 9ab32e6d0..d17bbcde7 100644 --- a/procps/Config.in +++ b/procps/Config.in | |||
@@ -43,6 +43,15 @@ config CONFIG_PS | |||
43 | help | 43 | help |
44 | ps gives a snapshot of the current processes. | 44 | ps gives a snapshot of the current processes. |
45 | 45 | ||
46 | config CONFIG_FEATURE_PS_WIDE | ||
47 | bool " Enable argument for wide output (-w)" | ||
48 | default n | ||
49 | depends on CONFIG_PS | ||
50 | help | ||
51 | Support argument 'w' for wide output. | ||
52 | If given once, 132 chars are printed and given more than | ||
53 | one, the length is unlimited. | ||
54 | |||
46 | config CONFIG_RENICE | 55 | config CONFIG_RENICE |
47 | bool "renice" | 56 | bool "renice" |
48 | default n | 57 | default n |
diff --git a/procps/ps.c b/procps/ps.c index 18a6db36f..a610bb218 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -4,19 +4,7 @@ | |||
4 | * | 4 | * |
5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify it | 7 | * Licensed under the GPL v2, see the file LICENSE in this tarball. |
8 | * under the terms of the GNU General Public License as published by the Free | ||
9 | * Software Foundation; either version 2 of the License, or (at your option) | ||
10 | * any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
15 | * more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License along with | ||
18 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | ||
19 | * Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | 8 | */ |
21 | 9 | ||
22 | #include <stdio.h> | 10 | #include <stdio.h> |
@@ -30,32 +18,47 @@ | |||
30 | #include <termios.h> | 18 | #include <termios.h> |
31 | #include <sys/ioctl.h> | 19 | #include <sys/ioctl.h> |
32 | #include "busybox.h" | 20 | #include "busybox.h" |
33 | #ifdef CONFIG_SELINUX | 21 | #if ENABLE_SELINUX |
34 | #include <selinux/selinux.h> /* for is_selinux_enabled() */ | 22 | #include <selinux/selinux.h> /* for is_selinux_enabled() */ |
35 | #endif | 23 | #endif |
36 | 24 | ||
37 | static const int TERMINAL_WIDTH = 79; /* not 80 in case terminal has linefold bug */ | 25 | #define TERMINAL_WIDTH 80 |
38 | |||
39 | |||
40 | 26 | ||
41 | extern int ps_main(int argc, char **argv) | 27 | extern int ps_main(int argc, char **argv) |
42 | { | 28 | { |
43 | procps_status_t * p; | 29 | procps_status_t * p; |
44 | int i, len; | 30 | int i, len, terminal_width; |
45 | int terminal_width = TERMINAL_WIDTH; | 31 | #if ENABLE_SELINUX |
46 | |||
47 | #ifdef CONFIG_SELINUX | ||
48 | int use_selinux = 0; | 32 | int use_selinux = 0; |
49 | security_context_t sid=NULL; | 33 | security_context_t sid=NULL; |
50 | if(is_selinux_enabled() && argv[1] && !strcmp(argv[1], "-c") ) | ||
51 | use_selinux = 1; | ||
52 | #endif | 34 | #endif |
53 | 35 | ||
54 | get_terminal_width_height(0, &terminal_width, NULL); | 36 | get_terminal_width_height(0, &terminal_width, NULL); |
37 | |||
38 | #if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX | ||
39 | /* handle arguments */ | ||
40 | /* bb_getopt_ulflags(argc, argv,) would force a leading dash */ | ||
41 | for (len = 1; len < argc; len++) { | ||
42 | char *c = argv[len]; | ||
43 | while (*c) { | ||
44 | if (ENABLE_FEATURE_PS_WIDE && *c == 'w') | ||
45 | /* if w is given once, GNU ps sets the width to 132, | ||
46 | * if w is given more than once, it is "unlimited" | ||
47 | */ | ||
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 | ||
54 | c++; | ||
55 | } | ||
56 | } | ||
57 | #endif | ||
58 | |||
55 | /* Go one less... */ | 59 | /* Go one less... */ |
56 | terminal_width--; | 60 | terminal_width--; |
57 | 61 | #if ENABLE_SELINUX | |
58 | #ifdef CONFIG_SELINUX | ||
59 | if (use_selinux) | 62 | if (use_selinux) |
60 | printf(" PID Context Stat Command\n"); | 63 | printf(" PID Context Stat Command\n"); |
61 | else | 64 | else |
@@ -64,8 +67,8 @@ extern int ps_main(int argc, char **argv) | |||
64 | 67 | ||
65 | while ((p = procps_scan(1)) != 0) { | 68 | while ((p = procps_scan(1)) != 0) { |
66 | char *namecmd = p->cmd; | 69 | char *namecmd = p->cmd; |
67 | #ifdef CONFIG_SELINUX | 70 | #if ENABLE_SELINUX |
68 | if ( use_selinux ) | 71 | if (use_selinux ) |
69 | { | 72 | { |
70 | char sbuf[128]; | 73 | char sbuf[128]; |
71 | len = sizeof(sbuf); | 74 | len = sizeof(sbuf); |
@@ -85,18 +88,19 @@ extern int ps_main(int argc, char **argv) | |||
85 | safe_strncpy(sbuf, "unknown",7); | 88 | safe_strncpy(sbuf, "unknown",7); |
86 | } | 89 | } |
87 | len = printf("%5d %-32s %s ", p->pid, sbuf, p->state); | 90 | len = printf("%5d %-32s %s ", p->pid, sbuf, p->state); |
88 | } | 91 | } |
89 | else | 92 | else |
90 | #endif | 93 | #endif |
91 | if(p->rss == 0) | 94 | if(p->rss == 0) |
92 | len = printf("%5d %-8s %s ", p->pid, p->user, p->state); | 95 | len = printf("%5d %-8s %s ", p->pid, p->user, p->state); |
93 | else | 96 | else |
94 | len = printf("%5d %-8s %6ld %s ", p->pid, p->user, p->rss, p->state); | 97 | len = printf("%5d %-8s %6ld %s ", p->pid, p->user, p->rss, p->state); |
98 | |||
95 | i = terminal_width-len; | 99 | i = terminal_width-len; |
96 | 100 | ||
97 | if(namecmd != 0 && namecmd[0] != 0) { | 101 | if(namecmd && namecmd[0]) { |
98 | if(i < 0) | 102 | if(i < 0) |
99 | i = 0; | 103 | i = 0; |
100 | if(strlen(namecmd) > i) | 104 | if(strlen(namecmd) > i) |
101 | namecmd[i] = 0; | 105 | namecmd[i] = 0; |
102 | printf("%s\n", namecmd); | 106 | printf("%s\n", namecmd); |
@@ -108,7 +112,9 @@ extern int ps_main(int argc, char **argv) | |||
108 | namecmd[i-2] = 0; | 112 | namecmd[i-2] = 0; |
109 | printf("[%s]\n", namecmd); | 113 | printf("[%s]\n", namecmd); |
110 | } | 114 | } |
111 | free(p->cmd); | 115 | /* no check needed, but to make valgrind happy.. */ |
116 | if (ENABLE_FEATURE_CLEAN_UP && p->cmd) | ||
117 | free(p->cmd); | ||
112 | } | 118 | } |
113 | return EXIT_SUCCESS; | 119 | return EXIT_SUCCESS; |
114 | } | 120 | } |