]> granicus.if.org Git - procps-ng/commitdiff
related: respond to VAL macro addition of context parm
authorJim Warner <james.warner@comcast.net>
Fri, 5 Aug 2016 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Sun, 7 Aug 2016 11:40:48 +0000 (21:40 +1000)
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>
pgrep.c
pidof.c
pmap.c
ps/common.h
ps/global.c
skill.c
top/top.c
vmstat.c
w.c

diff --git a/pgrep.c b/pgrep.c
index e0d98109931926a99fa08baadccbe7c802545a2a..8cbdf35a2f3ccba97f57bf30accfb58175e13653 100644 (file)
--- 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 24f3ecffa8e6c0ba5940017bfe2508a466d64cb7..09087fbbdbe71935104353fde28cf2e09a3b858a 100644 (file)
--- 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/<pid>/root symlink value */
diff --git a/pmap.c b/pmap.c
index c364abc3df1be2ad217904cf241e81fc057c725e..d1310f01b2f7542514986b4f725ea305fd504373 100644 (file)
--- a/pmap.c
+++ b/pmap.c
@@ -37,6 +37,8 @@
 #include "xalloc.h"
 #include <proc/procps.h>
 
+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 ; ) {
index 784446357e2d96892de557304d1bf402ebd10a82..0cdc878ee9dfa331fdf8983ccf2e126c3fbd21d6 100644 (file)
@@ -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);
index f2e56bc4bb27b015161a97b778611d8b6dd6f75e..6ecad377ab79c038ed9717c511a76350c210da1e 100644 (file)
@@ -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 7f7468f8d9b6a5d63c49670fc1e9d1aa5fb472ad..8ff30b798490ff9b1129164e2196cef5791c755b 100644 (file)
--- 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"));
 
index adfb083d85fdbd8c6a3e1b290d92e6df2b983320..cb31952eb16151bfd25fd70ff79eedfc1a6bf8a8 100644 (file)
--- 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)
         // --- <proc/pids.h> --------------------------------------------------
 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 <proc/pids.h> 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)
         // --- <proc/stat.h> --------------------------------------------------
 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)
 \f
 /*######  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;
 
index 6acdf74fa7650c6558d9a7180aade8e3970402f4..b1731b9c4ec48247f7962e4e8b99390385bf6bfb 100644 (file)
--- 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 9e956b36f96c3aa650c2f735584d927d3c06859e..71135207dbf5a3419f6dc9506ff2c4400c231699 100644 (file)
--- 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') {