diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-30 08:03:26 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-30 08:03:26 +0000 |
commit | f7d07b1723c15ee818f0c1f5cce96c55274024a6 (patch) | |
tree | b7f847c25ce3705d315ce4f0ac1b7976fae58cc6 /libbb/procps.c | |
parent | 42ee26d00cc9c9a6cf1f652a5351b30ac221fa34 (diff) | |
download | busybox-w32-f7d07b1723c15ee818f0c1f5cce96c55274024a6.tar.gz busybox-w32-f7d07b1723c15ee818f0c1f5cce96c55274024a6.tar.bz2 busybox-w32-f7d07b1723c15ee818f0c1f5cce96c55274024a6.zip |
killall, pidof: use argv0 for process matching too
top: show cmdline, not comm field
(fixes problems with re-execed applets showing as processes with name "exe",
and not being found by pidof/killall by applet name)
function old new delta
find_pid_by_name 98 156 +58
procps_scan 692 732 +40
top_main 2724 2762 +38
find_pair 164 180 +16
collect_int 114 123 +9
cmp_main 547 555 +8
collect_fork 112 119 +7
collect_ctx 112 119 +7
read_package_field 253 257 +4
passwd_main 1983 1985 +2
process_stdin 435 433 -2
xstrtoul_range_sfx 229 226 -3
get_next_block 1852 1849 -3
arith 2042 2033 -9
sv_main 1236 1226 -10
singlemount 4690 4672 -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 10/6 up/down: 189/-45) Total: 144 bytes
text data bss dec hex filename
734789 3028 14400 752217 b7a59 busybox_old
734933 3028 14400 752361 b7ae9 busybox_unstripped
Diffstat (limited to 'libbb/procps.c')
-rw-r--r-- | libbb/procps.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/libbb/procps.c b/libbb/procps.c index 5924d60a8..8413ce8a1 100644 --- a/libbb/procps.c +++ b/libbb/procps.c | |||
@@ -92,7 +92,7 @@ static int read_to_buf(const char *filename, void *buf) | |||
92 | return ret; | 92 | return ret; |
93 | } | 93 | } |
94 | 94 | ||
95 | procps_status_t* alloc_procps_scan(int flags) | 95 | procps_status_t *alloc_procps_scan(int flags) |
96 | { | 96 | { |
97 | procps_status_t* sp = xzalloc(sizeof(procps_status_t)); | 97 | procps_status_t* sp = xzalloc(sizeof(procps_status_t)); |
98 | sp->dir = xopendir("/proc"); | 98 | sp->dir = xopendir("/proc"); |
@@ -133,7 +133,7 @@ static char *skip_fields(char *str, int count) | |||
133 | #endif | 133 | #endif |
134 | 134 | ||
135 | void BUG_comm_size(void); | 135 | void BUG_comm_size(void); |
136 | procps_status_t* procps_scan(procps_status_t* sp, int flags) | 136 | procps_status_t *procps_scan(procps_status_t* sp, int flags) |
137 | { | 137 | { |
138 | struct dirent *entry; | 138 | struct dirent *entry; |
139 | char buf[PROCPS_BUFSIZE]; | 139 | char buf[PROCPS_BUFSIZE]; |
@@ -266,24 +266,31 @@ procps_status_t* procps_scan(procps_status_t* sp, int flags) | |||
266 | 266 | ||
267 | } | 267 | } |
268 | 268 | ||
269 | if (flags & PSSCAN_CMD) { | 269 | if (flags & (PSSCAN_CMD|PSSCAN_ARGV0)) { |
270 | free(sp->cmd); | 270 | if (sp->argv0) { |
271 | sp->cmd = NULL; | 271 | free(sp->argv0); |
272 | sp->argv0 = NULL; | ||
273 | } | ||
274 | if (sp->cmd) { | ||
275 | free(sp->cmd); | ||
276 | sp->cmd = NULL; | ||
277 | } | ||
272 | strcpy(filename_tail, "/cmdline"); | 278 | strcpy(filename_tail, "/cmdline"); |
279 | /* TODO: to get rid of size limits, read into malloc buf, | ||
280 | * then realloc it down to real size. */ | ||
273 | n = read_to_buf(filename, buf); | 281 | n = read_to_buf(filename, buf); |
274 | if (n <= 0) | 282 | if (n <= 0) |
275 | break; | 283 | break; |
276 | if (buf[n-1] == '\n') { | 284 | if (flags & PSSCAN_ARGV0) |
277 | if (!--n) | 285 | sp->argv0 = xstrdup(buf); |
278 | break; | 286 | if (flags & PSSCAN_CMD) { |
279 | buf[n] = '\0'; | 287 | do { |
288 | n--; | ||
289 | if ((unsigned char)(buf[n]) < ' ') | ||
290 | buf[n] = ' '; | ||
291 | } while (n); | ||
292 | sp->cmd = xstrdup(buf); | ||
280 | } | 293 | } |
281 | do { | ||
282 | n--; | ||
283 | if ((unsigned char)(buf[n]) < ' ') | ||
284 | buf[n] = ' '; | ||
285 | } while (n); | ||
286 | sp->cmd = xstrdup(buf); | ||
287 | } | 294 | } |
288 | break; | 295 | break; |
289 | } | 296 | } |