]> granicus.if.org Git - procps-ng/commitdiff
library: tweak that lxc container support a final time
authorJim Warner <james.warner@comcast.net>
Wed, 13 Feb 2019 06:00:00 +0000 (00:00 -0600)
committerCraig Small <csmall@enc.com.au>
Tue, 26 Mar 2019 08:55:30 +0000 (19:55 +1100)
Since the patch referenced below traded a compile-time
'sizeof' directive for a run-time 'strlen' call, there
is no need to declare lxc patterns as explicit arrays.

We'll also use the actual lxc patterns by omitting the
beginning slashes ('/') for both of those definitions.

And, looking to the future when most/all lxc users are
using the most recent lxc release, we will make things
slightly more efficient by reversing those two pattern
literals so the most recent pattern was checked first.

Of course, such a change only benefits tasks which are
running in a container. For the majority of processes,
both literals will be compared in that 'if' statement,
assuming the 'LXC' field is currently being displayed.

[ plus, a leftover parenthesis pair has been removed ]

Reference(s):
commit 288d759b8bdf22f194bdda88dbee0192bbc75bb0

Signed-off-by: Jim Warner <james.warner@comcast.net>
proc/readproc.c

index b522d1f6b51f034215a3fa56c2dad6e6ad84468b..73ca3469305c002c7e9cb09873742ffa752cc91a 100644 (file)
@@ -928,8 +928,8 @@ static char *lxc_containers (const char *path) {
     if (file2str(path, "cgroup", &ub) > 0) {
         /* 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
+        static const char *lxc_delm1 = "lxc.payload/";    // with lxc-3.1.0
+        static const char *lxc_delm2 = "lxc/";            // thru lxc-3.0.3
         const char *delim;
         char *p1;
 
@@ -946,7 +946,7 @@ static char *lxc_containers (const char *path) {
             if ((p2 = strchr(p1, '\n')))       // isolate a controller's line
                 *p2 = '\0';
             do {                               // deal with nested containers
-                p2 = p1 + (delim_len);
+                p2 = p1 + delim_len;
                 p1 = strstr(p2, delim);
             } while (p1);
             if ((p1 = strchr(p2, '/')))        // isolate name only substring