library: make sure that the proc_t is now fixed length
The former variable length structure created potential problems for library users like that referenced below. We will now parallel the same approach newlib uses for the configure options --enable-oomem & --with-systemd. Thus, the --enable-oomem and OOMEM_ENABLE #define have been eliminated and the --with-systemd option (#define WITH_SYSTEMD) will hereafter impact one function only. The proc_t struct itself will now *never* be impacted. Reference(s): https://gitlab.com/procps-ng/procps/issues/31 Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
@ -95,7 +95,6 @@ static inline void free_acquired (proc_t *p, int reuse) {
|
||||
if (p->cgroup) free((void*)*p->cgroup);
|
||||
if (p->supgid) free(p->supgid);
|
||||
if (p->supgrp) free(p->supgrp);
|
||||
#ifdef WITH_SYSTEMD
|
||||
if (p->sd_mach) free(p->sd_mach);
|
||||
if (p->sd_ouid) free(p->sd_ouid);
|
||||
if (p->sd_seat) free(p->sd_seat);
|
||||
@ -103,7 +102,6 @@ static inline void free_acquired (proc_t *p, int reuse) {
|
||||
if (p->sd_slice) free(p->sd_slice);
|
||||
if (p->sd_unit) free(p->sd_unit);
|
||||
if (p->sd_uunit) free(p->sd_uunit);
|
||||
#endif
|
||||
#ifdef QUICK_THREADS
|
||||
}
|
||||
#endif
|
||||
@ -467,7 +465,6 @@ static void supgrps_from_supgids (proc_t *p) {
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
#ifdef OOMEM_ENABLE
|
||||
static void oomscore2proc(const char* S, proc_t *restrict P)
|
||||
{
|
||||
sscanf(S, "%d", &P->oom_score);
|
||||
@ -477,7 +474,6 @@ static void oomadj2proc(const char* S, proc_t *restrict P)
|
||||
{
|
||||
sscanf(S, "%d", &P->oom_adj);
|
||||
}
|
||||
#endif
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const char *ns_names[] = {
|
||||
@ -520,8 +516,8 @@ static void ns2proc(const char *directory, proc_t *restrict p) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WITH_SYSTEMD
|
||||
static void sd2proc(proc_t *restrict p) {
|
||||
#ifdef WITH_SYSTEMD
|
||||
char buf[64];
|
||||
uid_t uid;
|
||||
|
||||
@ -534,7 +530,6 @@ static void sd2proc(proc_t *restrict p) {
|
||||
snprintf(buf, sizeof(buf), "%d", (int)uid);
|
||||
p->sd_ouid = strdup(buf);
|
||||
}
|
||||
|
||||
if (0 > sd_pid_get_session(p->tid, &p->sd_sess)) {
|
||||
p->sd_sess = strdup("-");
|
||||
p->sd_seat = strdup("-");
|
||||
@ -542,17 +537,22 @@ static void sd2proc(proc_t *restrict p) {
|
||||
if (0 > sd_session_get_seat(p->sd_sess, &p->sd_seat))
|
||||
p->sd_seat = strdup("-");
|
||||
}
|
||||
|
||||
if (0 > sd_pid_get_slice(p->tid, &p->sd_slice))
|
||||
p->sd_slice = strdup("-");
|
||||
|
||||
if (0 > sd_pid_get_unit(p->tid, &p->sd_unit))
|
||||
p->sd_unit = strdup("-");
|
||||
|
||||
if (0 > sd_pid_get_user_unit(p->tid, &p->sd_uunit))
|
||||
p->sd_uunit = strdup("-");
|
||||
}
|
||||
#else
|
||||
p->sd_mach = strdup("?");
|
||||
p->sd_ouid = strdup("?");
|
||||
p->sd_seat = strdup("?");
|
||||
p->sd_sess = strdup("?");
|
||||
p->sd_slice = strdup("?");
|
||||
p->sd_unit = strdup("?");
|
||||
p->sd_uunit = strdup("?");
|
||||
#endif
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@ -992,22 +992,18 @@ static proc_t* simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons
|
||||
} else
|
||||
p->cgroup = NULL;
|
||||
|
||||
#ifdef OOMEM_ENABLE
|
||||
if (unlikely(flags & PROC_FILLOOM)) {
|
||||
if (likely(file2str(path, "oom_score", &ub) != -1))
|
||||
oomscore2proc(ub.buf, p);
|
||||
if (likely(file2str(path, "oom_adj", &ub) != -1))
|
||||
oomadj2proc(ub.buf, p);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (unlikely(flags & PROC_FILLNS)) // read /proc/#/ns/*
|
||||
ns2proc(path, p);
|
||||
|
||||
#ifdef WITH_SYSTEMD
|
||||
if (unlikely(flags & PROC_FILLSYSTEMD)) // get sd-login.h stuff
|
||||
sd2proc(p);
|
||||
#endif
|
||||
|
||||
if (unlikely(flags & PROC_FILL_LXC)) // value the lxc name
|
||||
p->lxcname = lxc_containers(path);
|
||||
@ -1115,10 +1111,8 @@ static proc_t* simple_readtask(PROCTAB *restrict const PT, const proc_t *restric
|
||||
} else
|
||||
t->cgroup = NULL;
|
||||
|
||||
#ifdef WITH_SYSTEMD
|
||||
if (unlikely(flags & PROC_FILLSYSTEMD)) // get sd-login.h stuff
|
||||
sd2proc(t);
|
||||
#endif
|
||||
|
||||
if (unlikely(flags & PROC_FILL_LXC)) // value the lxc name
|
||||
t->lxcname = lxc_containers(path);
|
||||
@ -1138,7 +1132,6 @@ static proc_t* simple_readtask(PROCTAB *restrict const PT, const proc_t *restric
|
||||
if (t->supgid) free(t->supgid);
|
||||
t->supgid = p->supgid;
|
||||
t->supgrp = p->supgrp;
|
||||
#ifdef WITH_SYSTEMD
|
||||
t->sd_mach = p->sd_mach;
|
||||
t->sd_ouid = p->sd_ouid;
|
||||
t->sd_seat = p->sd_seat;
|
||||
@ -1146,20 +1139,17 @@ static proc_t* simple_readtask(PROCTAB *restrict const PT, const proc_t *restric
|
||||
t->sd_slice = p->sd_slice;
|
||||
t->sd_unit = p->sd_unit;
|
||||
t->sd_uunit = p->sd_uunit;
|
||||
#endif
|
||||
t->lxcname = p->lxcname;
|
||||
MK_THREAD(t);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef OOMEM_ENABLE
|
||||
if (unlikely(flags & PROC_FILLOOM)) {
|
||||
if (likely(file2str(path, "oom_score", &ub) != -1))
|
||||
oomscore2proc(ub.buf, t);
|
||||
if (likely(file2str(path, "oom_adj", &ub) != -1))
|
||||
oomadj2proc(ub.buf, t);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (unlikely(flags & PROC_FILLNS)) // read /proc/#/task/#/ns/*
|
||||
ns2proc(path, t);
|
||||
|
Reference in New Issue
Block a user