From f4666e1743cf68a08b9d09cc25015ff4a45dfdbe Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Fri, 29 Jun 2012 23:59:59 -0500 Subject: [PATCH] library: lift 1024 byte restriction on control groups The control group hierarchies for any particular task could conceivably grow quite large. However, the library might impose an arbitrary limit of 1024 bytes via fill_cgroup_cvt. Two utility buffers of 128 KiB each were already available for command line use. This commit simply trades the smaller 1024 byte stack based buffers for those much larger existing ones. Thus, truncation can be avoided with no additional run-time costs. Signed-off-by: Jim Warner --- proc/readproc.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/proc/readproc.c b/proc/readproc.c index 9ef587bf..1e9d3414 100644 --- a/proc/readproc.c +++ b/proc/readproc.c @@ -654,14 +654,13 @@ static char** vectorize_this_str (const char* src) { // It is similar to file2strvec except we filter and concatenate // the data into a single string represented as a single vector. static void fill_cgroup_cvt (const char* directory, proc_t *restrict p) { - #define vMAX ( sizeof(dbuf) - (int)(dst - dbuf) ) - char sbuf[1024], dbuf[1024]; + #define vMAX ( MAX_BUFSZ - (int)(dst - dst_buffer) ) char *src, *dst, *grp, *eob; - int tot, x, whackable_int = sizeof(dbuf); + int tot, x, whackable_int = MAX_BUFSZ; - *(dst = dbuf) = '\0'; // empty destination - tot = read_unvectored(sbuf, sizeof(sbuf), directory, "cgroup", '\0'); - for (src = sbuf, eob = sbuf + tot; src < eob; src += x) { + *(dst = dst_buffer) = '\0'; // empty destination + tot = read_unvectored(src_buffer, MAX_BUFSZ, directory, "cgroup", '\0'); + for (src = src_buffer, eob = src_buffer + tot; src < eob; src += x) { x = 1; // loop assist if (!*src) continue; x = strlen((grp = src)); @@ -669,10 +668,10 @@ static void fill_cgroup_cvt (const char* directory, proc_t *restrict p) { #if 0 grp += strspn(grp, "0123456789:"); // jump past group number #endif - dst += snprintf(dst, vMAX, "%s", (dst > dbuf) ? "," : ""); + dst += snprintf(dst, vMAX, "%s", (dst > dst_buffer) ? "," : ""); dst += escape_str(dst, grp, vMAX, &whackable_int); } - p->cgroup = vectorize_this_str(dbuf[0] ? dbuf : "-"); + p->cgroup = vectorize_this_str(dst_buffer[0] ? dst_buffer : "-"); #undef vMAX } -- 2.40.0