From: Jim Warner Date: Thu, 28 Jun 2012 05:00:01 +0000 (-0500) Subject: library: standardize handling of cgroup, supgid X-Git-Tag: v3.3.4~46 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8b64b36bbfa8dc038727a37e3e8ce97bd8efeb1f;p=procps-ng library: standardize handling of cgroup, supgid Some inconsistencies have emerged during development of support for these relatively new proc_t fields. For example, a PROC_FILLCGROUP flag (via file2strvec) could return NULL in cgroup whereas PROC_EDITCGRPCVT (via fill_cgroup_cvt) *almost* guaranteed a return address (as is true for PROC_EDITCMDLCVT and cmdline). But even PROC_EDITCGRPCVT could return NULL if the kernel version was less than 2.6.24. Then with NULL ps would display a "-" while top would show "n/a". And while unlikely, with the PROC_FILLSTATUS flag (via status2proc) a NULL supgid address was theoretically possible and both ps and top would then show "n/a". This commit standardizes the following usage: . PROC_FILLSTATUS (via status2proc) guarantees a valid supgid address representing either a true comma delimited list or "-" . PROC_FILLCGROUP plus PROC_EDITCGRPCVT (via fill_cgroup_cvt) guarantees a cgroup single vector representing either a true control group hierarchy or "-" And as was true before, the following remains true: PROC_FILLCOM or PROC_FILLARG (via file2strvec) may return a NULL cmdline pointer . PROC_FILLCGROUP (via file2strvec) may return a NULL cgroup pointer . PROC_FILLCOM or PROC_FILLARG plus PROC_EDITCMDLCVT (via fill_cmdline_cvt) guarantees a cmdline single vector representing either a true command line or a bracketed program name . PROC_FILLSTATUS plus PROC_FILLSUPGRP (via supgrps_from_supgids) guarantees a valid supgrp address representing either a true comma delimited list or "-" Signed-off-by: Jim Warner --- diff --git a/proc/readproc.c b/proc/readproc.c index 36658d95..9ef587bf 100644 --- a/proc/readproc.c +++ b/proc/readproc.c @@ -362,8 +362,7 @@ ENTER(0x220); for ( ; j; j--) if (' ' == P->supgid[j]) P->supgid[j] = ','; - } else - P->supgid = xstrdup("-"); + } continue; } case_CapBnd: @@ -412,6 +411,9 @@ ENTER(0x220); P->tid = Pid; } + if (!P->supgid) + P->supgid = xstrdup("-"); + LEAVE(0x220); } @@ -793,8 +795,7 @@ static proc_t* simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons } else p->cmdline = NULL; - if ((flags & PROC_FILLCGROUP) // read /proc/#/cgroup - && linux_version_code >= LINUX_VERSION(2,6,24)) { + if ((flags & PROC_FILLCGROUP)) { // read /proc/#/cgroup if (flags & PROC_EDITCGRPCVT) fill_cgroup_cvt(path, p); else @@ -903,8 +904,7 @@ static proc_t* simple_readtask(PROCTAB *restrict const PT, const proc_t *restric } else t->cmdline = NULL; - if ((flags & PROC_FILLCGROUP) // read /proc/#/task/#/cgroup - && linux_version_code >= LINUX_VERSION(2,6,24)) { + if ((flags & PROC_FILLCGROUP)) { // read /proc/#/task/#/cgroup if (flags & PROC_EDITCGRPCVT) fill_cgroup_cvt(path, t); else