library: stop treating lxcname differently, <PIDS> api

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>
This commit is contained in:
Jim Warner 2016-07-01 00:00:00 -05:00 committed by Craig Small
parent eff9fbc06e
commit 8cd1214aac
3 changed files with 11 additions and 11 deletions

View 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 },

View 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;

View 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;