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 <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2012-06-29 23:59:59 -05:00 committed by Craig Small
parent f114476a94
commit f4666e1743

View File

@ -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
}