From 5a65447e3090908b4bad645c84e37298ca7a7449 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sun, 10 Jun 2007 17:11:59 +0000 Subject: top: add config option and code for global CPU % display --- libbb/procps.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'libbb') diff --git a/libbb/procps.c b/libbb/procps.c index be0d61b..1e2495a 100644 --- a/libbb/procps.c +++ b/libbb/procps.c @@ -79,8 +79,15 @@ const char* get_cached_groupname(gid_t gid) static int read_to_buf(const char *filename, void *buf) { - ssize_t ret; - ret = open_read_close(filename, buf, PROCPS_BUFSIZE-1); + int fd; + /* open_read_close() would do two reads, checking for EOF. + * When you have 10000 /proc/$NUM/stat to read, it isn't desirable */ + ssize_t ret = -1; + fd = open(filename, O_RDONLY); + if (fd >= 0) { + ret = read(fd, buf, PROCPS_BUFSIZE-1); + close(fd); + } ((char *)buf)[ret > 0 ? ret : 0] = '\0'; return ret; } -- cgit v1.1