]> granicus.if.org Git - procps-ng/commitdiff
library: stop treating lxcname differently, <PIDS> api
authorJim Warner <james.warner@comcast.net>
Fri, 1 Jul 2016 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Sat, 2 Jul 2016 06:33:01 +0000 (16:33 +1000)
Unlike other cached string fields (such as USER name),
that lxcname field was defined as 'const char *'. This
required a custom 'set' function using a cast in order
to avoid a compiler warning regarding that assignment.

So this commit brings lxcname into line with all those
other cached string fields. And while we're at it, the
reason some string fields have no 'freefunc' will also
be explained with some new comments in the Item_table.

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

index adaf477e796ef0105123c6b932768bc9e6ec077f..23c97af861e8ae0b9976507909364d72644fff6d 100644 (file)
@@ -180,7 +180,7 @@ REG_set(ID_SUID,          u_int,   suid)
 REG_set(ID_SUSER,         str,     suser)
 REG_set(ID_TGID,          s_int,   tgid)
 REG_set(ID_TPGID,         s_int,   tpgid)
-setDECL(LXCNAME)      { (void)I; R->result.str = (char *)P->lxcname; }
+REG_set(LXCNAME,          str,     lxcname)
 REG_set(MEM_CODE,         sl_int,  trs)
 CVT_set(MEM_CODE_KIB,     sl_int,  trs)
 REG_set(MEM_DATA,         sl_int,  drs)
@@ -406,29 +406,29 @@ static struct {
     { RS(FLT_MIN),           f_stat,     NULL,      QS(sl_int),    0        },
     { RS(FLT_MIN_C),         f_stat,     NULL,      QS(sl_int),    0        },
     { RS(FLT_MIN_DELTA),     f_stat,     NULL,      QS(sl_int),    +1       },
-    { RS(ID_EGID),           0,          NULL,      QS(u_int),     0        }, // oldflags: free w/ simple_read...
+    { RS(ID_EGID),           0,          NULL,      QS(u_int),     0        }, // oldflags: free w/ simple_read
     { RS(ID_EGROUP),         f_grp,      NULL,      QS(str),       0        },
-    { RS(ID_EUID),           0,          NULL,      QS(u_int),     0        }, // oldflags: free w/ simple_read...
-    { RS(ID_EUSER),          f_usr,      NULL,      QS(str),       0        },
+    { RS(ID_EUID),           0,          NULL,      QS(u_int),     0        }, // oldflags: free w/ simple_read
+    { RS(ID_EUSER),          f_usr,      NULL,      QS(str),       0        }, // freefunc NULL w/ cached string
     { RS(ID_FGID),           f_status,   NULL,      QS(u_int),     0        },
     { RS(ID_FGROUP),         x_ogroup,   NULL,      QS(str),       0        },
     { RS(ID_FUID),           f_status,   NULL,      QS(u_int),     0        },
-    { RS(ID_FUSER),          x_ouser,    NULL,      QS(str),       0        },
+    { RS(ID_FUSER),          x_ouser,    NULL,      QS(str),       0        }, // freefunc NULL w/ cached string
     { RS(ID_PGRP),           f_stat,     NULL,      QS(s_int),     0        },
     { RS(ID_PID),            0,          NULL,      QS(s_int),     0        }, // oldflags: free w/ simple_nextpid
     { RS(ID_PPID),           f_either,   NULL,      QS(s_int),     0        },
     { RS(ID_RGID),           f_status,   NULL,      QS(u_int),     0        },
     { RS(ID_RGROUP),         x_ogroup,   NULL,      QS(str),       0        },
     { RS(ID_RUID),           f_status,   NULL,      QS(u_int),     0        },
-    { RS(ID_RUSER),          x_ouser,    NULL,      QS(str),       0        },
+    { RS(ID_RUSER),          x_ouser,    NULL,      QS(str),       0        }, // freefunc NULL w/ cached string
     { RS(ID_SESSION),        f_stat,     NULL,      QS(s_int),     0        },
     { RS(ID_SGID),           f_status,   NULL,      QS(u_int),     0        },
     { RS(ID_SGROUP),         x_ogroup,   NULL,      QS(str),       0        },
     { RS(ID_SUID),           f_status,   NULL,      QS(u_int),     0        },
-    { RS(ID_SUSER),          x_ouser,    NULL,      QS(str),       0        },
+    { RS(ID_SUSER),          x_ouser,    NULL,      QS(str),       0        }, // freefunc NULL w/ cached string
     { RS(ID_TGID),           0,          NULL,      QS(s_int),     0        }, // oldflags: free w/ simple_nextpid
     { RS(ID_TPGID),          f_stat,     NULL,      QS(s_int),     0        },
-    { RS(LXCNAME),           f_lxc,      NULL,      QS(str),       0        },
+    { RS(LXCNAME),           f_lxc,      NULL,      QS(str),       0        }, // freefunc NULL w/ cached string
     { RS(MEM_CODE),          f_statm,    NULL,      QS(sl_int),    0        },
     { RS(MEM_CODE_KIB),      f_statm,    NULL,      QS(sl_int),    0        },
     { RS(MEM_DATA),          f_statm,    NULL,      QS(sl_int),    0        },
index 98d3da143d170c1ae7252a9491e50639b32111d9..a434be03fec7e2b566706523eb67a80827e941d9 100644 (file)
@@ -775,7 +775,7 @@ static void fill_environ_cvt (const char* directory, proc_t *restrict p) {
     // Provide the means to value proc_t.lxcname (perhaps only with "-") while
     // tracking all names already seen thus avoiding the overhead of repeating
     // malloc() and free() calls.
-static const char *lxc_containers (const char *path) {
+static char *lxc_containers (const char *path) {
     static struct utlbuf_s ub = { NULL, 0 };   // util buffer for whole cgroup
     static char lxc_none[] = "-";
     /*
@@ -800,7 +800,7 @@ static const char *lxc_containers (const char *path) {
         if ((p1 = strstr(ub.buf, lxc_delm))) {
             static struct lxc_ele {
                 struct lxc_ele *next;
-                const char *name;
+                char *name;
             } *anchor = NULL;
             struct lxc_ele *ele = anchor;
             char *p2;
index 65e771c627faa1501d72208a23f2e0f94127e681..647c8578920ea4bf7162595a4283c60c0246b537 100644 (file)
@@ -169,7 +169,7 @@ typedef struct proc_t {
         *sd_slice,      // n/a             systemd slice unit
         *sd_unit,       // n/a             systemd system unit id
         *sd_uunit;      // n/a             systemd user unit id
-    const char
+    char
         *lxcname;       // n/a             lxc container name
 } proc_t;