diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-30 14:47:41 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-30 14:47:41 +0000 |
commit | 98ebab8b768d4651d8db2f46a0cd6bd53012c8e6 (patch) | |
tree | 2f491e67f1f49a31b0cfeeaabb032b646b8d808c /libbb | |
parent | 8b1409896d3224fec477bc372c4dceaebe6d6351 (diff) | |
download | busybox-w32-98ebab8b768d4651d8db2f46a0cd6bd53012c8e6.tar.gz busybox-w32-98ebab8b768d4651d8db2f46a0cd6bd53012c8e6.tar.bz2 busybox-w32-98ebab8b768d4651d8db2f46a0cd6bd53012c8e6.zip |
top,ps: improve /proc/PID/cmdinfo reading code
function old new delta
display_status - 1231 +1231
read_cmdline - 101 +101
parse_conf 1284 1303 +19
arith 2033 2042 +9
collect_blk 467 474 +7
fsck_main 1909 1911 +2
dhcprelay_main 1125 1122 -3
singlemount 4555 4547 -8
read_close 50 36 -14
get_lcm 123 105 -18
ed_main 3111 3084 -27
func_args 73 28 -45
procps_scan 732 658 -74
top_main 2187 899 -1288
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/8 up/down: 1369/-1477) Total: -108 bytes
text data bss dec hex filename
676048 2744 13968 692760 a9218 busybox_old
675940 2744 13968 692652 a91ac busybox_unstripped
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/procps.c | 35 | ||||
-rw-r--r-- | libbb/read.c | 6 |
2 files changed, 37 insertions, 4 deletions
diff --git a/libbb/procps.c b/libbb/procps.c index 8413ce8a1..1987e98fd 100644 --- a/libbb/procps.c +++ b/libbb/procps.c | |||
@@ -102,7 +102,7 @@ procps_status_t *alloc_procps_scan(int flags) | |||
102 | void free_procps_scan(procps_status_t* sp) | 102 | void free_procps_scan(procps_status_t* sp) |
103 | { | 103 | { |
104 | closedir(sp->dir); | 104 | closedir(sp->dir); |
105 | free(sp->cmd); | 105 | free(sp->argv0); |
106 | USE_SELINUX(free(sp->context);) | 106 | USE_SELINUX(free(sp->context);) |
107 | free(sp); | 107 | free(sp); |
108 | } | 108 | } |
@@ -266,6 +266,7 @@ procps_status_t *procps_scan(procps_status_t* sp, int flags) | |||
266 | 266 | ||
267 | } | 267 | } |
268 | 268 | ||
269 | #if 0 /* PSSCAN_CMD is not used */ | ||
269 | if (flags & (PSSCAN_CMD|PSSCAN_ARGV0)) { | 270 | if (flags & (PSSCAN_CMD|PSSCAN_ARGV0)) { |
270 | if (sp->argv0) { | 271 | if (sp->argv0) { |
271 | free(sp->argv0); | 272 | free(sp->argv0); |
@@ -292,10 +293,42 @@ procps_status_t *procps_scan(procps_status_t* sp, int flags) | |||
292 | sp->cmd = xstrdup(buf); | 293 | sp->cmd = xstrdup(buf); |
293 | } | 294 | } |
294 | } | 295 | } |
296 | #else | ||
297 | if (flags & PSSCAN_ARGV0) { | ||
298 | if (sp->argv0) { | ||
299 | free(sp->argv0); | ||
300 | sp->argv0 = NULL; | ||
301 | } | ||
302 | strcpy(filename_tail, "/cmdline"); | ||
303 | n = read_to_buf(filename, buf); | ||
304 | if (n <= 0) | ||
305 | break; | ||
306 | if (flags & PSSCAN_ARGV0) | ||
307 | sp->argv0 = xstrdup(buf); | ||
308 | } | ||
309 | #endif | ||
295 | break; | 310 | break; |
296 | } | 311 | } |
297 | return sp; | 312 | return sp; |
298 | } | 313 | } |
314 | |||
315 | void read_cmdline(char *buf, int col, unsigned pid, const char *comm) | ||
316 | { | ||
317 | ssize_t sz; | ||
318 | char filename[sizeof("/proc//cmdline") + sizeof(int)*3]; | ||
319 | |||
320 | sprintf(filename, "/proc/%u/cmdline", pid); | ||
321 | sz = open_read_close(filename, buf, col); | ||
322 | if (sz > 0) { | ||
323 | buf[sz] = '\0'; | ||
324 | while (--sz >= 0) | ||
325 | if ((unsigned char)(buf[sz]) < ' ') | ||
326 | buf[sz] = ' '; | ||
327 | } else { | ||
328 | snprintf(buf, col, "[%s]", comm); | ||
329 | } | ||
330 | } | ||
331 | |||
299 | /* from kernel: | 332 | /* from kernel: |
300 | // pid comm S ppid pgid sid tty_nr tty_pgrp flg | 333 | // pid comm S ppid pgid sid tty_nr tty_pgrp flg |
301 | sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \ | 334 | sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \ |
diff --git a/libbb/read.c b/libbb/read.c index 05bf754e0..502d407c4 100644 --- a/libbb/read.c +++ b/libbb/read.c | |||
@@ -124,11 +124,11 @@ char *xmalloc_reads(int fd, char *buf) | |||
124 | 124 | ||
125 | ssize_t read_close(int fd, void *buf, size_t size) | 125 | ssize_t read_close(int fd, void *buf, size_t size) |
126 | { | 126 | { |
127 | int e; | 127 | /*int e;*/ |
128 | size = full_read(fd, buf, size); | 128 | size = full_read(fd, buf, size); |
129 | e = errno; | 129 | /*e = errno;*/ |
130 | close(fd); | 130 | close(fd); |
131 | errno = e; | 131 | /*errno = e;*/ |
132 | return size; | 132 | return size; |
133 | } | 133 | } |
134 | 134 | ||