Rewritten cgroup support and suppressed root cgroup

Bug-Redhat: https://bugzilla.redhat.com/show_bug.cgi?id=593267
Signed-off-by: Jan Görig <jgorig@redhat.com>
This commit is contained in:
Jan Görig 2011-01-19 12:16:56 +01:00
parent 8fde4af11d
commit 59679bc2a2
2 changed files with 40 additions and 27 deletions

View File

@ -493,9 +493,12 @@ static char** file2strvec(const char* directory, const char* what) {
} }
endbuf = rbuf + tot; /* count space for pointers */ endbuf = rbuf + tot; /* count space for pointers */
align = (sizeof(char*)-1) - ((tot + sizeof(char*)-1) & (sizeof(char*)-1)); align = (sizeof(char*)-1) - ((tot + sizeof(char*)-1) & (sizeof(char*)-1));
for (c = 0, p = rbuf; p < endbuf; p++) for (c = 0, p = rbuf; p < endbuf; p++) {
if (!*p) if (!*p || *p == '\n')
c += sizeof(char*); c += sizeof(char*);
if (*p == '\n')
*p = 0;
}
c += sizeof(char*); /* one extra for NULL term */ c += sizeof(char*); /* one extra for NULL term */
rbuf = xrealloc(rbuf, tot + c + align); /* make room for ptrs AT END */ rbuf = xrealloc(rbuf, tot + c + align); /* make room for ptrs AT END */
@ -635,14 +638,8 @@ static proc_t* simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons
else else
p->environ = NULL; p->environ = NULL;
if(linux_version_code>=LINUX_VERSION(2,6,24) && (flags & PROC_FILLCGROUP)) { if(linux_version_code>=LINUX_VERSION(2,6,24) && (flags & PROC_FILLCGROUP))
p->cgroup = file2strvec(path, "cgroup"); /* read /proc/#/cgroup */ p->cgroup = file2strvec(path, "cgroup"); /* read /proc/#/cgroup */
if(p->cgroup && *p->cgroup) {
int i = strlen(*p->cgroup);
if( (*p->cgroup)[i-1]=='\n' )
(*p->cgroup)[i-1] = ' '; //little hack to remove trailing \n
}
}
else else
p->cgroup = NULL; p->cgroup = NULL;

View File

@ -359,23 +359,39 @@ static int pr_args(char *restrict const outbuf, const proc_t *restrict const pp)
} }
static int pr_cgroup(char *restrict const outbuf,const proc_t *restrict const pp) { static int pr_cgroup(char *restrict const outbuf,const proc_t *restrict const pp) {
if(pp->cgroup && *pp->cgroup) {
char *endp = outbuf; char *endp = outbuf;
int rightward = max_rightward; int rightward = max_rightward;
if(forest_prefix){
int fh = forest_helper(outbuf); if(pp->cgroup) {
endp += fh; char **pcgroup = pp->cgroup;
rightward -= fh;
} while(*pcgroup != NULL) {
if(rightward>1){ //Skip root cgroups
*endp++ = ' '; if(!**pcgroup || (*pcgroup)[strlen(*pcgroup)-1] == '/') {
rightward--; pcgroup++;
endp += escape_str(endp, *pp->cgroup, OUTBUF_SIZE, &rightward); continue;
}
return max_rightward-rightward;
} }
//Skip initial cgroup number
char *ccgroup = strchr(*pcgroup, ':');
if(ccgroup == NULL)
ccgroup = *pcgroup;
else else
ccgroup++;
if(endp != outbuf)
endp += escape_str(endp, ";", OUTBUF_SIZE, &rightward);
endp += escape_str(endp, ccgroup, OUTBUF_SIZE, &rightward);
pcgroup++;
}
}
if(endp == outbuf)
return pr_nop(outbuf,pp); return pr_nop(outbuf,pp);
return (int)(endp-outbuf);
} }
/* "ucomm" is the same thing: short unless -f */ /* "ucomm" is the same thing: short unless -f */