library: adapt readproc for the latest lxc conventions
The merge request shown below prompted (thankfully) an examination of our lxc containers logic in readproc.c. As it turns out, the lxc folks changed that eyecatcher used to identify containers within a task cgroup file. So this patch, with little extra cost, will enable the libprocps lxc_containers() guy to handle both strings. [ additionally, I was shocked to find lxc allows the ] [ eyecatcher to be changed at ./configure time. such ] [ a provision has always existed. unfortunately, the ] [ changed value was only available to root, assuming ] [ one wished to tackle that undocumented liblxc api. ] Reference(s): . what prompted lxc support reevaluation https://gitlab.com/procps-ng/procps/merge_requests/82 . original lxc support introduced commit 0557504f9cb84987f9d9038755404be017bdb7d1 Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
dbe12b5400
commit
f67127e728
@ -910,22 +910,28 @@ static const char *lxc_containers (const char *path) {
|
||||
1:cpuset,cpu,cpuacct,devices,freezer,net_cls,blkio,perf_event,net_prio:/lxc/lxc-P
|
||||
*/
|
||||
if (file2str(path, "cgroup", &ub) > 0) {
|
||||
static const char lxc_delm[] = "/lxc/";
|
||||
/* ouch, next two defaults could be changed at lxc ./configure time
|
||||
( and a changed 'lxc.cgroup.pattern' is only available to root ) */
|
||||
static const char lxc_delm1[] = "/lxc/"; // thru lxc-3.0.3
|
||||
static const char lxc_delm2[] = "/lxc.payload/"; // with lxc-3.1.0
|
||||
const char *delim;
|
||||
char *p1;
|
||||
|
||||
if ((p1 = strstr(ub.buf, lxc_delm))) {
|
||||
if ((p1 = strstr(ub.buf, (delim = lxc_delm1)))
|
||||
|| ((p1 = strstr(ub.buf, (delim = lxc_delm2))))) {
|
||||
static struct lxc_ele {
|
||||
struct lxc_ele *next;
|
||||
const char *name;
|
||||
} *anchor = NULL;
|
||||
struct lxc_ele *ele = anchor;
|
||||
int delim_len = strlen(delim);
|
||||
char *p2;
|
||||
|
||||
if ((p2 = strchr(p1, '\n'))) // isolate a controller's line
|
||||
*p2 = '\0';
|
||||
do { // deal with nested containers
|
||||
p2 = p1 + (sizeof(lxc_delm)-1);
|
||||
p1 = strstr(p2, lxc_delm);
|
||||
p2 = p1 + (delim_len);
|
||||
p1 = strstr(p2, delim);
|
||||
} while (p1);
|
||||
if ((p1 = strchr(p2, '/'))) // isolate name only substring
|
||||
*p1 = '\0';
|
||||
|
Loading…
x
Reference in New Issue
Block a user