related: respond to VAL macro addition of context parm

Since the VAL macro now requires a 4th parameter, this
commit simply adds the 'info' context structure to it.

In some cases, that context structure needed to become
global, since it was referenced in multiple functions.

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2016-08-05 00:00:00 -05:00 committed by Craig Small
parent 6cafe3abec
commit e0515e23e7
9 changed files with 47 additions and 45 deletions

View File

@ -471,9 +471,9 @@ static regex_t * do_regcomp (void)
static struct el * select_procs (int *num) static struct el * select_procs (int *num)
{ {
#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, stack) #define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, stack, info)
#define PIDS_GETULL(e) PIDS_VAL(EU_ ## e, ull_int, stack) #define PIDS_GETULL(e) PIDS_VAL(EU_ ## e, ull_int, stack, info)
#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, stack) #define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, stack, info)
struct pids_info *info=NULL; struct pids_info *info=NULL;
struct procps_namespaces nsp; struct procps_namespaces nsp;
struct pids_stack *stack; struct pids_stack *stack;

View File

@ -151,9 +151,9 @@ static void select_procs (void)
exe_link = root_link = NULL; exe_link = root_link = NULL;
while ((stack = procps_pids_get(info, PIDS_FETCH_TASKS_ONLY))) { while ((stack = procps_pids_get(info, PIDS_FETCH_TASKS_ONLY))) {
char *p_cmd = PIDS_VAL(rel_cmd, str, stack), char *p_cmd = PIDS_VAL(rel_cmd, str, stack, info),
**p_cmdline = PIDS_VAL(rel_cmdline, strv, stack); **p_cmdline = PIDS_VAL(rel_cmdline, strv, stack, info);
int tid = PIDS_VAL(rel_pid, s_int, stack); int tid = PIDS_VAL(rel_pid, s_int, stack, info);
if (opt_rootdir_check) { if (opt_rootdir_check) {
/* get the /proc/<pid>/root symlink value */ /* get the /proc/<pid>/root symlink value */

19
pmap.c
View File

@ -37,6 +37,8 @@
#include "xalloc.h" #include "xalloc.h"
#include <proc/procps.h> #include <proc/procps.h>
static struct pids_info *Pids_info;
enum pids_item Pid_items[] = { enum pids_item Pid_items[] = {
PIDS_ID_PID, PIDS_ID_TGID, PIDS_ID_PID, PIDS_ID_TGID,
PIDS_CMDLINE, PIDS_ADDR_START_STACK }; PIDS_CMDLINE, PIDS_ADDR_START_STACK };
@ -238,8 +240,8 @@ static char *mapping_name(struct pids_stack *p, unsigned long addr,
} }
cp = _(" [ anon ]"); cp = _(" [ anon ]");
if (PIDS_VAL(start_stack, ul_int, p) >= addr if (PIDS_VAL(start_stack, ul_int, p, Pids_info) >= addr
&& (PIDS_VAL(start_stack, ul_int, p) <= addr + len)) && (PIDS_VAL(start_stack, ul_int, p, Pids_info) <= addr + len))
cp = _(" [ stack ]"); cp = _(" [ stack ]");
return cp; return cp;
} }
@ -534,14 +536,14 @@ static int one_proc (struct pids_stack *p)
unsigned long long total_shared_dirty = 0ull; unsigned long long total_shared_dirty = 0ull;
int maxw1=0, maxw2=0, maxw3=0, maxw4=0, maxw5=0; int maxw1=0, maxw2=0, maxw3=0, maxw4=0, maxw5=0;
printf("%u: %s\n", PIDS_VAL(tgid, s_int, p), PIDS_VAL(cmdline, str, p)); printf("%u: %s\n", PIDS_VAL(tgid, s_int, p, Pids_info), PIDS_VAL(cmdline, str, p, Pids_info));
if (x_option || X_option || c_option) { if (x_option || X_option || c_option) {
sprintf(buf, "/proc/%u/smaps", PIDS_VAL(tgid, s_int, p)); sprintf(buf, "/proc/%u/smaps", PIDS_VAL(tgid, s_int, p, Pids_info));
if ((fp = fopen(buf, "r")) == NULL) if ((fp = fopen(buf, "r")) == NULL)
return 1; return 1;
} else { } else {
sprintf(buf, "/proc/%u/maps", PIDS_VAL(tgid, s_int, p)); sprintf(buf, "/proc/%u/maps", PIDS_VAL(tgid, s_int, p, Pids_info));
if ((fp = fopen(buf, "r")) == NULL) if ((fp = fopen(buf, "r")) == NULL)
return 1; return 1;
} }
@ -995,7 +997,6 @@ static char *get_default_rc_filename(void)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct pids_info *info = NULL;
struct pids_fetch *pids_fetch; struct pids_fetch *pids_fetch;
unsigned *pidlist; unsigned *pidlist;
int reap_count, user_count; int reap_count, user_count;
@ -1136,7 +1137,7 @@ int main(int argc, char **argv)
} }
} }
} }
if (procps_pids_new(&info, Pid_items, 4)) if (procps_pids_new(&Pids_info, Pid_items, 4))
xerrx(EXIT_FAILURE, _("library failed pids statistics")); xerrx(EXIT_FAILURE, _("library failed pids statistics"));
pidlist = xmalloc(sizeof(pid_t) * argc); pidlist = xmalloc(sizeof(pid_t) * argc);
@ -1161,7 +1162,7 @@ int main(int argc, char **argv)
discover_shm_minor(); discover_shm_minor();
if (!(pids_fetch = procps_pids_select(info, pidlist, user_count, PIDS_SELECT_PID))) if (!(pids_fetch = procps_pids_select(Pids_info, pidlist, user_count, PIDS_SELECT_PID)))
xerrx(EXIT_FAILURE, _("library failed pids statistics")); xerrx(EXIT_FAILURE, _("library failed pids statistics"));
for (reap_count = 0; reap_count < pids_fetch->counts->total; reap_count++) { for (reap_count = 0; reap_count < pids_fetch->counts->total; reap_count++) {
@ -1169,7 +1170,7 @@ int main(int argc, char **argv)
} }
free(pidlist); free(pidlist);
procps_pids_unref(&info); procps_pids_unref(&Pids_info);
/* cleaning the list used for the -c/-X/-XX modes */ /* cleaning the list used for the -c/-X/-XX modes */
for (listnode = listhead; listnode != NULL ; ) { for (listnode = listhead; listnode != NULL ; ) {

View File

@ -34,7 +34,7 @@
/* a 'results stack value' extractor macro /* a 'results stack value' extractor macro
where: E=rel enum, T=data type, S=stack */ where: E=rel enum, T=data type, S=stack */
#define rSv(E,T,S) PIDS_VAL(rel_ ## E, T, S) #define rSv(E,T,S) PIDS_VAL(rel_ ## E, T, S, Pids_info)
#define namREL(e) rel_ ## e #define namREL(e) rel_ ## e
#define makEXT(e) extern int namREL(e); #define makEXT(e) extern int namREL(e);

View File

@ -488,7 +488,7 @@ void reset_global(void){
bsd_c_option = 0; bsd_c_option = 0;
bsd_e_option = 0; bsd_e_option = 0;
cached_euid = geteuid(); cached_euid = geteuid();
cached_tty = PIDS_VAL(0, s_int, p); cached_tty = PIDS_VAL(0, s_int, p, Pids_info);
/* forest_prefix must be all zero because of POSIX */ /* forest_prefix must be all zero because of POSIX */
forest_type = 0; forest_type = 0;
format_flags = 0; /* -l -f l u s -j... */ format_flags = 0; /* -l -f l u s -j... */

17
skill.c
View File

@ -69,6 +69,8 @@ if(!thing##s) thing##s = xmalloc(sizeof(*thing##s)*saved_argc); \
thing##s[thing##_count++] = addme; \ thing##s[thing##_count++] = addme; \
}while(0) }while(0)
struct pids_info *Pids_info;
enum pids_item items[] = { enum pids_item items[] = {
PIDS_ID_PID, PIDS_ID_PID,
PIDS_ID_EUID, PIDS_ID_EUID,
@ -164,8 +166,8 @@ static int match_ns(const int pid)
static int ask_user(struct pids_stack *stack) static int ask_user(struct pids_stack *stack)
{ {
#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, stack) #define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, stack, Pids_info)
#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, stack) #define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, stack, Pids_info)
char *buf=NULL; char *buf=NULL;
size_t len=0; size_t len=0;
@ -262,16 +264,15 @@ static void show_lists(void)
static void scan_procs(struct run_time_conf_t *run_time) static void scan_procs(struct run_time_conf_t *run_time)
{ {
#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, reap->stacks[i]) #define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, reap->stacks[i], Pids_info)
#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, reap->stacks[i]) #define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, reap->stacks[i], Pids_info)
struct pids_info *info=NULL;
struct pids_fetch *reap; struct pids_fetch *reap;
int i, total_procs; int i, total_procs;
if (procps_pids_new(&info, items, 6) < 0) if (procps_pids_new(&Pids_info, items, 6) < 0)
xerrx(EXIT_FAILURE, xerrx(EXIT_FAILURE,
_("Unable to create pid info structure")); _("Unable to create pid Pids_info structure"));
if ((reap = procps_pids_reap(info, PIDS_FETCH_TASKS_ONLY)) == NULL) if ((reap = procps_pids_reap(Pids_info, PIDS_FETCH_TASKS_ONLY)) == NULL)
xerrx(EXIT_FAILURE, xerrx(EXIT_FAILURE,
_("Unable to load process information")); _("Unable to load process information"));

View File

@ -208,7 +208,7 @@ enum Rel_memitems {
mem_FRE, mem_USE, mem_TOT, mem_QUE, mem_BUF, mem_AVL, mem_FRE, mem_USE, mem_TOT, mem_QUE, mem_BUF, mem_AVL,
swp_TOT, swp_FRE, swp_USE }; swp_TOT, swp_FRE, swp_USE };
// mem stack results extractor macro, where e=rel enum // mem stack results extractor macro, where e=rel enum
#define MEM_VAL(e) MEMINFO_VAL(e, ul_int, Mem_stack) #define MEM_VAL(e) MEMINFO_VAL(e, ul_int, Mem_stack, Mem_ctx)
// --- <proc/pids.h> -------------------------------------------------- // --- <proc/pids.h> --------------------------------------------------
static struct pids_info *Pids_ctx; static struct pids_info *Pids_ctx;
static int Pids_itms_cur; // 'current' max (<= Fieldstab) static int Pids_itms_cur; // 'current' max (<= Fieldstab)
@ -218,7 +218,7 @@ static struct pids_fetch *Pids_reap; // for reap or select
// pid stack results extractor macro, where e=our EU enum, t=type, s=stack // pid stack results extractor macro, where e=our EU enum, t=type, s=stack
// ( we'll exploit that <proc/pids.h> provided macro as much as possible ) // ( we'll exploit that <proc/pids.h> provided macro as much as possible )
// ( but many functions use their own unique tailored version for access ) // ( but many functions use their own unique tailored version for access )
#define PID_VAL(e,t,s) PIDS_VAL(Fieldstab[ e ].erel, t, s) #define PID_VAL(e,t,s) PIDS_VAL(Fieldstab[ e ].erel, t, s, Pids_ctx)
// --- <proc/stat.h> -------------------------------------------------- // --- <proc/stat.h> --------------------------------------------------
static struct stat_info *Stat_ctx; static struct stat_info *Stat_ctx;
static struct stat_reaped *Stat_reap; static struct stat_reaped *Stat_reap;
@ -232,8 +232,8 @@ enum Rel_statitems {
stat_ID, stat_NU, stat_US, stat_SY, stat_NI, stat_ID, stat_NU, stat_US, stat_SY, stat_NI,
stat_IL, stat_IO, stat_IR, stat_SI, stat_ST }; stat_IL, stat_IO, stat_IR, stat_SI, stat_ST };
// cpu/node stack results extractor macros, where e=rel enum, x=index // cpu/node stack results extractor macros, where e=rel enum, x=index
#define CPU_VAL(e,x) STAT_VAL(e, s_int, Stat_reap->cpus->stacks[x]) #define CPU_VAL(e,x) STAT_VAL(e, s_int, Stat_reap->cpus->stacks[x], Stat_ctx)
#define NOD_VAL(e,x) STAT_VAL(e, s_int, Stat_reap->nodes->stacks[x]) #define NOD_VAL(e,x) STAT_VAL(e, s_int, Stat_reap->nodes->stacks[x], Stat_ctx)
/*###### Tiny useful routine(s) ########################################*/ /*###### Tiny useful routine(s) ########################################*/
@ -4611,7 +4611,7 @@ all_done:
* display and thus requiring the cpu summary toggle */ * display and thus requiring the cpu summary toggle */
static void summary_hlp (struct stat_stack *this, const char *pfx) { static void summary_hlp (struct stat_stack *this, const char *pfx) {
// a tailored 'results stack value' extractor macro // a tailored 'results stack value' extractor macro
#define rSv(E) STAT_VAL(E, sl_int, this) #define rSv(E) STAT_VAL(E, sl_int, this, Stat_ctx)
SIC_t u_frme, s_frme, n_frme, i_frme, w_frme, x_frme, y_frme, z_frme, tot_frme; SIC_t u_frme, s_frme, n_frme, i_frme, w_frme, x_frme, y_frme, z_frme, tot_frme;
float scale; float scale;

View File

@ -323,11 +323,11 @@ static unsigned long unitConvert(unsigned long size)
static void new_format(void) static void new_format(void)
{ {
#define TICv(E) STAT_VAL(E, ull_int, stat_stack) #define TICv(E) STAT_VAL(E, ull_int, stat_stack, stat_info)
#define DTICv(E) STAT_VAL(E, sl_int, stat_stack) #define DTICv(E) STAT_VAL(E, sl_int, stat_stack, stat_info)
#define SYSv(E) STAT_VAL(E, ul_int, stat_stack) #define SYSv(E) STAT_VAL(E, ul_int, stat_stack, stat_info)
#define MEMv(E) MEMINFO_VAL(E, ul_int, mem_stack) #define MEMv(E) MEMINFO_VAL(E, ul_int, mem_stack, mem_info)
#define DSYSv(E) STAT_VAL(E, s_int, stat_stack) #define DSYSv(E) STAT_VAL(E, s_int, stat_stack, stat_info)
const char format[] = const char format[] =
"%2lu %2lu %6lu %6lu %6lu %6lu %4u %4u %5u %5u %4u %4u %2u %2u %2u %2u %2u"; "%2lu %2lu %6lu %6lu %6lu %6lu %4u %4u %5u %5u %4u %4u %2u %2u %2u %2u %2u";
const char wide_format[] = const char wide_format[] =
@ -528,7 +528,7 @@ static void diskpartition_header(const char *partition_name)
static void diskpartition_format(const char *partition_name) static void diskpartition_format(const char *partition_name)
{ {
#define partVAL(x) DISKSTATS_VAL(x, ul_int, stack) #define partVAL(x) DISKSTATS_VAL(x, ul_int, stack, disk_stat)
struct diskstats_info *disk_stat; struct diskstats_info *disk_stat;
struct diskstats_stack *stack; struct diskstats_stack *stack;
struct diskstats_result *got; struct diskstats_result *got;
@ -625,7 +625,7 @@ static void diskheader(void)
static void diskformat(void) static void diskformat(void)
{ {
#define diskVAL(e,t) DISKSTATS_VAL(e, t, reap->stacks[j]) #define diskVAL(e,t) DISKSTATS_VAL(e, t, reap->stacks[j], disk_stat)
struct diskstats_info *disk_stat; struct diskstats_info *disk_stat;
struct diskstats_reap *reap; struct diskstats_reap *reap;
int i, j; int i, j;
@ -742,7 +742,7 @@ static void slabformat (void)
static void disksum_format(void) static void disksum_format(void)
{ {
#define diskVAL(e,t) DISKSTATS_VAL(e, t, reap->stacks[j]) #define diskVAL(e,t) DISKSTATS_VAL(e, t, reap->stacks[j], disk_stat)
struct diskstats_info *disk_stat; struct diskstats_info *disk_stat;
struct diskstats_reap *reap; struct diskstats_reap *reap;
int j, disk_count, part_count; int j, disk_count, part_count;
@ -799,9 +799,9 @@ static void disksum_format(void)
static void sum_format(void) static void sum_format(void)
{ {
#define TICv(E) STAT_VAL(E, ull_int, stat_stack) #define TICv(E) STAT_VAL(E, ull_int, stat_stack, stat_info)
#define SYSv(E) STAT_VAL(E, ul_int, stat_stack) #define SYSv(E) STAT_VAL(E, ul_int, stat_stack, stat_info)
#define MEMv(E) unitConvert(STAT_VAL(E, ul_int, mem_stack)) #define MEMv(E) unitConvert(MEMINFO_VAL(E, ul_int, mem_stack, mem_info))
struct stat_info *stat_info = NULL; struct stat_info *stat_info = NULL;
struct vmstat_info *vm_info = NULL; struct vmstat_info *vm_info = NULL;
struct meminfo_info *mem_info = NULL; struct meminfo_info *mem_info = NULL;

8
w.c
View File

@ -343,9 +343,9 @@ static int find_best_proc(
unsigned long long *restrict const pcpu, unsigned long long *restrict const pcpu,
char *cmdline) char *cmdline)
{ {
#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, reap->stacks[i]) #define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, reap->stacks[i], info)
#define PIDS_GETULL(e) PIDS_VAL(EU_ ## e, ull_int, reap->stacks[i]) #define PIDS_GETULL(e) PIDS_VAL(EU_ ## e, ull_int, reap->stacks[i], info)
#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, reap->stacks[i]) #define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, reap->stacks[i], info)
unsigned uid = ~0U; unsigned uid = ~0U;
int found_utpid = 0; int found_utpid = 0;
int i, total_procs, line; int i, total_procs, line;
@ -404,7 +404,7 @@ static int find_best_proc(
} }
if (PIDS_GETINT(TTY) != line) if (PIDS_GETINT(TTY) != line)
continue; continue;
(*jcpu) += PIDS_VAL(EU_TICS_ALL, ull_int, reap->stacks[i]); (*jcpu) += PIDS_VAL(EU_TICS_ALL, ull_int, reap->stacks[i], info);
if (!(secondbest_time && PIDS_GETULL(START) <= secondbest_time)) { if (!(secondbest_time && PIDS_GETULL(START) <= secondbest_time)) {
secondbest_time = PIDS_GETULL(START); secondbest_time = PIDS_GETULL(START);
if (cmdline[0] == '-' && cmdline[1] == '\0') { if (cmdline[0] == '-' && cmdline[1] == '\0') {