diff --git a/pgrep.c b/pgrep.c index e0d98109..8cbdf35a 100644 --- a/pgrep.c +++ b/pgrep.c @@ -471,9 +471,9 @@ static regex_t * do_regcomp (void) static struct el * select_procs (int *num) { -#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, stack) -#define PIDS_GETULL(e) PIDS_VAL(EU_ ## e, ull_int, stack) -#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, stack) +#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, stack, info) +#define PIDS_GETULL(e) PIDS_VAL(EU_ ## e, ull_int, stack, info) +#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, stack, info) struct pids_info *info=NULL; struct procps_namespaces nsp; struct pids_stack *stack; diff --git a/pidof.c b/pidof.c index 24f3ecff..09087fbb 100644 --- a/pidof.c +++ b/pidof.c @@ -151,9 +151,9 @@ static void select_procs (void) exe_link = root_link = NULL; while ((stack = procps_pids_get(info, PIDS_FETCH_TASKS_ONLY))) { - char *p_cmd = PIDS_VAL(rel_cmd, str, stack), - **p_cmdline = PIDS_VAL(rel_cmdline, strv, stack); - int tid = PIDS_VAL(rel_pid, s_int, stack); + char *p_cmd = PIDS_VAL(rel_cmd, str, stack, info), + **p_cmdline = PIDS_VAL(rel_cmdline, strv, stack, info); + int tid = PIDS_VAL(rel_pid, s_int, stack, info); if (opt_rootdir_check) { /* get the /proc//root symlink value */ diff --git a/pmap.c b/pmap.c index c364abc3..d1310f01 100644 --- a/pmap.c +++ b/pmap.c @@ -37,6 +37,8 @@ #include "xalloc.h" #include +static struct pids_info *Pids_info; + enum pids_item Pid_items[] = { PIDS_ID_PID, PIDS_ID_TGID, PIDS_CMDLINE, PIDS_ADDR_START_STACK }; @@ -238,8 +240,8 @@ static char *mapping_name(struct pids_stack *p, unsigned long addr, } cp = _(" [ anon ]"); - if (PIDS_VAL(start_stack, ul_int, p) >= addr - && (PIDS_VAL(start_stack, ul_int, p) <= addr + len)) + if (PIDS_VAL(start_stack, ul_int, p, Pids_info) >= addr + && (PIDS_VAL(start_stack, ul_int, p, Pids_info) <= addr + len)) cp = _(" [ stack ]"); return cp; } @@ -534,14 +536,14 @@ static int one_proc (struct pids_stack *p) unsigned long long total_shared_dirty = 0ull; 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) { - 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) return 1; } 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) return 1; } @@ -995,7 +997,6 @@ static char *get_default_rc_filename(void) int main(int argc, char **argv) { - struct pids_info *info = NULL; struct pids_fetch *pids_fetch; unsigned *pidlist; 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")); pidlist = xmalloc(sizeof(pid_t) * argc); @@ -1161,7 +1162,7 @@ int main(int argc, char **argv) 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")); for (reap_count = 0; reap_count < pids_fetch->counts->total; reap_count++) { @@ -1169,7 +1170,7 @@ int main(int argc, char **argv) } free(pidlist); - procps_pids_unref(&info); + procps_pids_unref(&Pids_info); /* cleaning the list used for the -c/-X/-XX modes */ for (listnode = listhead; listnode != NULL ; ) { diff --git a/ps/common.h b/ps/common.h index 78444635..0cdc878e 100644 --- a/ps/common.h +++ b/ps/common.h @@ -34,7 +34,7 @@ /* a 'results stack value' extractor macro 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 makEXT(e) extern int namREL(e); diff --git a/ps/global.c b/ps/global.c index f2e56bc4..6ecad377 100644 --- a/ps/global.c +++ b/ps/global.c @@ -488,7 +488,7 @@ void reset_global(void){ bsd_c_option = 0; bsd_e_option = 0; 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_type = 0; format_flags = 0; /* -l -f l u s -j... */ diff --git a/skill.c b/skill.c index 7f7468f8..8ff30b79 100644 --- a/skill.c +++ b/skill.c @@ -69,6 +69,8 @@ if(!thing##s) thing##s = xmalloc(sizeof(*thing##s)*saved_argc); \ thing##s[thing##_count++] = addme; \ }while(0) +struct pids_info *Pids_info; + enum pids_item items[] = { PIDS_ID_PID, PIDS_ID_EUID, @@ -164,8 +166,8 @@ static int match_ns(const int pid) static int ask_user(struct pids_stack *stack) { -#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, stack) -#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, stack) +#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, stack, Pids_info) +#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, stack, Pids_info) char *buf=NULL; size_t len=0; @@ -262,16 +264,15 @@ static void show_lists(void) 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_GETSTR(e) PIDS_VAL(EU_ ## e, str, reap->stacks[i]) - struct pids_info *info=NULL; +#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], Pids_info) struct pids_fetch *reap; int i, total_procs; - if (procps_pids_new(&info, items, 6) < 0) + if (procps_pids_new(&Pids_info, items, 6) < 0) xerrx(EXIT_FAILURE, - _("Unable to create pid info structure")); - if ((reap = procps_pids_reap(info, PIDS_FETCH_TASKS_ONLY)) == NULL) + _("Unable to create pid Pids_info structure")); + if ((reap = procps_pids_reap(Pids_info, PIDS_FETCH_TASKS_ONLY)) == NULL) xerrx(EXIT_FAILURE, _("Unable to load process information")); diff --git a/top/top.c b/top/top.c index adfb083d..cb31952e 100644 --- a/top/top.c +++ b/top/top.c @@ -208,7 +208,7 @@ enum Rel_memitems { mem_FRE, mem_USE, mem_TOT, mem_QUE, mem_BUF, mem_AVL, swp_TOT, swp_FRE, swp_USE }; // 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) // --- -------------------------------------------------- static struct pids_info *Pids_ctx; 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 // ( we'll exploit that provided macro as much as possible ) // ( 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) // --- -------------------------------------------------- static struct stat_info *Stat_ctx; static struct stat_reaped *Stat_reap; @@ -232,8 +232,8 @@ enum Rel_statitems { stat_ID, stat_NU, stat_US, stat_SY, stat_NI, stat_IL, stat_IO, stat_IR, stat_SI, stat_ST }; // 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 NOD_VAL(e,x) STAT_VAL(e, s_int, Stat_reap->nodes->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], Stat_ctx) /*###### Tiny useful routine(s) ########################################*/ @@ -4611,7 +4611,7 @@ all_done: * display and thus requiring the cpu summary toggle */ static void summary_hlp (struct stat_stack *this, const char *pfx) { // 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; float scale; diff --git a/vmstat.c b/vmstat.c index 6acdf74f..b1731b9c 100644 --- a/vmstat.c +++ b/vmstat.c @@ -323,11 +323,11 @@ static unsigned long unitConvert(unsigned long size) static void new_format(void) { -#define TICv(E) STAT_VAL(E, ull_int, stat_stack) -#define DTICv(E) STAT_VAL(E, sl_int, stat_stack) -#define SYSv(E) STAT_VAL(E, ul_int, stat_stack) -#define MEMv(E) MEMINFO_VAL(E, ul_int, mem_stack) -#define DSYSv(E) STAT_VAL(E, s_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, stat_info) +#define SYSv(E) STAT_VAL(E, ul_int, stat_stack, stat_info) +#define MEMv(E) MEMINFO_VAL(E, ul_int, mem_stack, mem_info) +#define DSYSv(E) STAT_VAL(E, s_int, stat_stack, stat_info) const char format[] = "%2lu %2lu %6lu %6lu %6lu %6lu %4u %4u %5u %5u %4u %4u %2u %2u %2u %2u %2u"; const char wide_format[] = @@ -528,7 +528,7 @@ static void diskpartition_header(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_stack *stack; struct diskstats_result *got; @@ -625,7 +625,7 @@ static void diskheader(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_reap *reap; int i, j; @@ -742,7 +742,7 @@ static void slabformat (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_reap *reap; int j, disk_count, part_count; @@ -799,9 +799,9 @@ static void disksum_format(void) static void sum_format(void) { -#define TICv(E) STAT_VAL(E, ull_int, stat_stack) -#define SYSv(E) STAT_VAL(E, ul_int, stat_stack) -#define MEMv(E) unitConvert(STAT_VAL(E, ul_int, mem_stack)) +#define TICv(E) STAT_VAL(E, ull_int, stat_stack, stat_info) +#define SYSv(E) STAT_VAL(E, ul_int, stat_stack, stat_info) +#define MEMv(E) unitConvert(MEMINFO_VAL(E, ul_int, mem_stack, mem_info)) struct stat_info *stat_info = NULL; struct vmstat_info *vm_info = NULL; struct meminfo_info *mem_info = NULL; diff --git a/w.c b/w.c index 9e956b36..71135207 100644 --- a/w.c +++ b/w.c @@ -343,9 +343,9 @@ static int find_best_proc( unsigned long long *restrict const pcpu, char *cmdline) { -#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, reap->stacks[i]) -#define PIDS_GETULL(e) PIDS_VAL(EU_ ## e, ull_int, reap->stacks[i]) -#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, 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], info) +#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, reap->stacks[i], info) unsigned uid = ~0U; int found_utpid = 0; int i, total_procs, line; @@ -404,7 +404,7 @@ static int find_best_proc( } if (PIDS_GETINT(TTY) != line) 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)) { secondbest_time = PIDS_GETULL(START); if (cmdline[0] == '-' && cmdline[1] == '\0') {