X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=libbb%2Fprocps.c;h=fd19621db00be01eedf72d2402ad2875abadbc7d;hb=e357d2ae6833e3ca306f3aa6e12c6ddf2ff1eae2;hp=7d49d83ce6561663c0e12f7cbeec966585563507;hpb=defc1ea34074e7882724c460260d307cdf981a70;p=oweals%2Fbusybox.git diff --git a/libbb/procps.c b/libbb/procps.c index 7d49d83ce..fd19621db 100644 --- a/libbb/procps.c +++ b/libbb/procps.c @@ -46,7 +46,7 @@ static int get_cached(cache_t *cp, unsigned id) if (cp->cache[i].id == id) return i; i = cp->size++; - cp->cache = xrealloc(cp->cache, cp->size * sizeof(*cp->cache)); + cp->cache = xrealloc_vector(cp->cache, 2, i); cp->cache[i++].id = id; return -i; } @@ -60,7 +60,7 @@ static char* get_cached(cache_t *cp, unsigned id, ug_func* fp) if (cp->cache[i].id == id) return cp->cache[i].name; i = cp->size++; - cp->cache = xrealloc(cp->cache, cp->size * sizeof(*cp->cache)); + cp->cache = xrealloc_vector(cp->cache, 2, i); cp->cache[i].id = id; /* Never fails. Generates numeric string if name isn't found */ fp(cp->cache[i].name, sizeof(cp->cache[i].name), id); @@ -78,7 +78,7 @@ const char* FAST_FUNC get_cached_groupname(gid_t gid) #define PROCPS_BUFSIZE 1024 -static int FAST_FUNC read_to_buf(const char *filename, void *buf) +static int read_to_buf(const char *filename, void *buf) { int fd; /* open_read_close() would do two reads, checking for EOF. @@ -308,7 +308,7 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) FILE *file; strcpy(filename_tail, "/smaps"); - file = fopen(filename, "r"); + file = fopen_for_read(filename); if (!file) break; while (fgets(buf, sizeof(buf), file)) { @@ -385,16 +385,15 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) n = read_to_buf(filename, buf); if (n <= 0) break; -#if ENABLE_PGREP || ENABLE_PKILL if (flags & PSSCAN_ARGVN) { - do { - n--; - if (buf[n] == '\0') - buf[n] = ' '; - } while (n); + sp->argv_len = n; + sp->argv0 = xmalloc(n + 1); + memcpy(sp->argv0, buf, n + 1); + /* sp->argv0[n] = '\0'; - buf has it */ + } else { + sp->argv_len = 0; + sp->argv0 = xstrdup(buf); } -#endif - sp->argv0 = xstrdup(buf); } #endif break;