From 288d759b8bdf22f194bdda88dbee0192bbc75bb0 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Thu, 10 Jan 2019 00:00:00 -0600 Subject: [PATCH] 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 --- proc/readproc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/proc/readproc.c b/proc/readproc.c index af02446d..b522d1f6 100644 --- a/proc/readproc.c +++ b/proc/readproc.c @@ -926,22 +926,28 @@ static 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; 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';