summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Görig <jgorig@redhat.com>2011-01-19 12:16:56 +0100
committerJan Görig <jgorig@redhat.com>2011-02-10 13:40:29 +0100
commit59679bc2a27438993e33bd3711938ce02e8e569d (patch)
treebfdd9aaad5fd2fdc87784e5ee9d6704aceab7bb0
parent8fde4af11d06b6af7fc52974a63464c9d9c13695 (diff)
downloadprocps-ng-59679bc2a27438993e33bd3711938ce02e8e569d.tar.gz
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>
-rw-r--r--proc/readproc.c15
-rw-r--r--ps/output.c52
2 files changed, 40 insertions, 27 deletions
diff --git a/proc/readproc.c b/proc/readproc.c
index f199c26..890e77a 100644
--- a/proc/readproc.c
+++ b/proc/readproc.c
@@ -493,9 +493,12 @@ static char** file2strvec(const char* directory, const char* what) {
}
endbuf = rbuf + tot; /* count space for pointers */
align = (sizeof(char*)-1) - ((tot + sizeof(char*)-1) & (sizeof(char*)-1));
- for (c = 0, p = rbuf; p < endbuf; p++)
- if (!*p)
+ for (c = 0, p = rbuf; p < endbuf; p++) {
+ if (!*p || *p == '\n')
c += sizeof(char*);
+ if (*p == '\n')
+ *p = 0;
+ }
c += sizeof(char*); /* one extra for NULL term */
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
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 */
- 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
p->cgroup = NULL;
diff --git a/ps/output.c b/ps/output.c
index 338cf1a..6a79e45 100644
--- a/ps/output.c
+++ b/ps/output.c
@@ -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) {
- if(pp->cgroup && *pp->cgroup) {
- char *endp = outbuf;
- int rightward=max_rightward;
- if(forest_prefix){
- int fh = forest_helper(outbuf);
- endp += fh;
- rightward -= fh;
- }
- if(rightward>1){
- *endp++ = ' ';
- rightward--;
- endp += escape_str(endp, *pp->cgroup, OUTBUF_SIZE, &rightward);
- }
- return max_rightward-rightward;
- }
- else
- return pr_nop(outbuf,pp);
+ char *endp = outbuf;
+ int rightward = max_rightward;
+
+ if(pp->cgroup) {
+ char **pcgroup = pp->cgroup;
+
+ while(*pcgroup != NULL) {
+ //Skip root cgroups
+ if(!**pcgroup || (*pcgroup)[strlen(*pcgroup)-1] == '/') {
+ pcgroup++;
+ continue;
+ }
+
+ //Skip initial cgroup number
+ char *ccgroup = strchr(*pcgroup, ':');
+ if(ccgroup == NULL)
+ ccgroup = *pcgroup;
+ 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 (int)(endp-outbuf);
}
/* "ucomm" is the same thing: short unless -f */
@@ -1312,7 +1328,7 @@ static const format_struct format_array[] = {
{"bsdtime", "TIME", pr_bsdtime, sr_nop, 6, 0, LNX, ET|RIGHT},
{"c", "C", pr_c, sr_pcpu, 2, 0, SUN, ET|RIGHT},
{"caught", "CAUGHT", pr_sigcatch, sr_nop, 9, 0, BSD, TO|SIGNAL}, /*sigcatch*/
-{"cgroup", "CGROUP", pr_cgroup, sr_nop, 27, CGRP, LNX, PO|UNLIMITED},
+{"cgroup", "CGROUP", pr_cgroup, sr_nop, 27,CGRP, LNX, PO|UNLIMITED},
{"class", "CLS", pr_class, sr_sched, 3, 0, XXX, TO|LEFT},
{"cls", "CLS", pr_class, sr_sched, 3, 0, HPU, TO|RIGHT}, /*says HPUX or RT*/
{"cmaj_flt", "-", pr_nop, sr_cmaj_flt, 1, 0, LNX, AN|RIGHT},