Commit 32db4e99 authored by jim warner's avatar jim warner Committed by Craig Small

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):
#31Signed-off-by: jim warner's avatarJim Warner <james.warner@comcast.net>
parent 10503c03
......@@ -182,14 +182,6 @@ AC_ARG_ENABLE([examples],
)
AM_CONDITIONAL(EXAMPLE_FILES, test "x$enable_examples" = xyes)
AC_ARG_ENABLE([oomem],
AS_HELP_STRING([--enable-oomem], [add out-of-memory fields to the library and top]),
[], [enable_oomem=no]
)
if test "x$enable_oomem" = xyes; then
AC_DEFINE(OOMEM_ENABLE, 1, [add out-of-memory fields to the library and top])
fi
AC_ARG_ENABLE([sigwinch],
AS_HELP_STRING([--enable-sigwinch], [reduce impact of x-windows resize operations on top]),
[], [enable_sigwinch=no]
......
......@@ -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);
......
......@@ -167,14 +167,11 @@ typedef struct proc_t {
tpgid, // stat terminal process group id
exit_signal, // stat might not be SIGCHLD
processor; // stat current (or most recent?) CPU
#ifdef OOMEM_ENABLE
int
oom_score, // oom_score (badness for OOM killer)
oom_adj; // oom_adj (adjustment to OOM score)
#endif
long
ns[NUM_NS]; // (ns subdir) inode number of namespaces
#ifdef WITH_SYSTEMD
char
*sd_mach, // n/a systemd vm/container name
*sd_ouid, // n/a systemd session owner uid
......@@ -183,7 +180,6 @@ 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
#endif
const char
*lxcname; // n/a lxc container name
} proc_t;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment