related: fix inconsistencies in result type references

This patch is a response to errors found in those type
references now that our library allows for validation.

In two cases, former assignments to a result structure
could no longer employ that VAL macro if validation is
active. Thus, direct reference to some stack was used.

For the record, those instances were to be found here:
. ps - uses PIDS_extra to store the cooked pcpu values
. top - uses PIDS_extra to store the forest view level

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 e3270d463d
commit 105058ae2d
4 changed files with 17 additions and 12 deletions

View File

@ -267,7 +267,8 @@ static void value_this_proc_pcpu(proc_t *buf){
seconds = rSv(TIME_ELAPSED, ull_int, buf);
if(seconds) pcpu = (used_jiffies * 1000ULL / Hertz) / seconds;
rSv(extra, ul_int, buf) = pcpu;
// if xtra-procps-debug.h active, can't use PIDS_VAL as base due to assignment
buf->head[rel_extra].result.ul_int = pcpu;
}
}
@ -545,7 +546,6 @@ static void finalize_stacks (void)
chkREL(ID_SUID)
chkREL(ID_TGID)
chkREL(STATE)
chkREL(TIME_START)
chkREL(TTY)
// needed to creata an enhanced 'stat/state'
chkREL(ID_PGRP)
@ -561,8 +561,11 @@ static void finalize_stacks (void)
chkREL(SIGNALS)
chkREL(SIGPENDING)
// needed with loss of defunct 'cook_time' macros
chkREL(TICS_ALL)
chkREL(TICS_ALL_C)
chkREL(TIME_ALL)
chkREL(TIME_ELAPSED)
chkREL(TIME_START)
// special items with 'extra' used as former pcpu
chkREL(extra)
chkREL(noop)

View File

@ -52,7 +52,6 @@
#include "top.h"
#include "top_nls.h"
/*###### Miscellaneous global stuff ####################################*/
/* The original and new terminal definitions
@ -4447,10 +4446,11 @@ static int Tree_idx; // frame_make resets to zero
* This little recursive guy is the real forest view workhorse.
* He fills in the Tree_ppt array and also sets the child indent
* level which is stored in an 'extra' result struct as a u_int. */
static void forest_adds (const int self, int level) {
static void forest_adds (const int self, unsigned level) {
// tailored 'results stack value' extractor macros
#define rSv(E,X) PID_VAL(E, s_int, Seed_ppt[X])
#define rLevel PID_VAL(eu_XTRA, u_int, Tree_ppt[Tree_idx])
// if xtra-procps-debug.h active, can't use PID_VAL as base due to assignment
#define rLevel Tree_ppt[Tree_idx]->head[Fieldstab[eu_XTRA].erel].result.u_int
int i;
if (Tree_idx < PIDSmaxt) { // immunize against insanity
@ -4965,7 +4965,7 @@ static const char *task_show (const WIN_t *q, struct pids_stack *p) {
break;
/* ul_int, scale_pcnt */
case EU_MEM:
cp = scale_pcnt((float)rSv(EU_RES, ul_int) * 100 / MEM_VAL(mem_TOT), W, Jn);
cp = scale_pcnt((float)rSv(EU_MEM, ul_int) * 100 / MEM_VAL(mem_TOT), W, Jn);
break;
/* ul_int, make_str with special handling */
case EU_FLG:

View File

@ -632,8 +632,8 @@ static void diskformat(void)
time_t the_time;
struct tm *tm_ptr;
char timebuf[32];
const char format[] = "%-5s %6lu %6lu %7lu %7lu %6lu %6lu %7lu %7lu %6lu %6lu";
const char wide_format[] = "%-5s %9lu %9lu %11lu %11lu %9lu %9lu %11lu %11lu %7lu %7lu";
const char format[] = "%-5s %6lu %6lu %7lu %7lu %6lu %6lu %7lu %7lu %6d %6lu";
const char wide_format[] = "%-5s %9lu %9lu %11lu %11lu %9lu %9lu %11lu %11lu %7d %7lu";
if (procps_diskstats_new(&disk_stat) < 0)
xerrx(EXIT_FAILURE, _("Unable to create diskstat structure"));
@ -664,7 +664,7 @@ static void diskformat(void)
diskVAL(disk_WRITE_MERGE, ul_int),
diskVAL(disk_WRITE_SECT, ul_int),
diskVAL(disk_WRITE_TIME, ul_int),
diskVAL(disk_IO, ul_int) / 1000,
diskVAL(disk_IO, s_int) / 1000,
diskVAL(disk_IO_TIME, ul_int) / 1000);
if (t_option)
printf(" %s\n", timebuf);
@ -775,7 +775,7 @@ static void disksum_format(void)
merged_writes += diskVAL(disk_WRITE_MERGE, ul_int);
written_sectors += diskVAL(disk_WRITE_SECT, ul_int);
milli_writing += diskVAL(disk_WRITE_TIME, ul_int);
inprogress_IO += diskVAL(disk_IO, ul_int) / 1000;
inprogress_IO += diskVAL(disk_IO, s_int) / 1000;
milli_spent_IO += diskVAL(disk_IO_TIME, ul_int) / 1000;
weighted_milli_spent_IO += diskVAL(disk_IO_WTIME, ul_int) / 1000;
}

6
w.c
View File

@ -344,6 +344,7 @@ static int find_best_proc(
char *cmdline)
{
#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, reap->stacks[i], info)
#define PIDS_GETUNT(e) PIDS_VAL(EU_ ## e, u_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;
@ -413,8 +414,8 @@ static int find_best_proc(
}
}
if (
(!ignoreuser && uid != PIDS_GETINT(EUID)
&& uid != PIDS_GETINT(RUID))
(!ignoreuser && uid != PIDS_GETUNT(EUID)
&& uid != PIDS_GETUNT(RUID))
|| (PIDS_GETINT(PGRP) != PIDS_GETINT(TPGID))
|| (PIDS_GETULL(START) <= best_time)
)
@ -426,6 +427,7 @@ static int find_best_proc(
procps_pids_unref(&info);
return found_utpid;
#undef PIDS_GETINT
#undef PIDS_GETUNT
#undef PIDS_GETULL
#undef PIDS_GETSTR
}