top: Check graph_cpus, graph_mems, and sum... REVERTED

The variables graph_cpus, graph_mems & summ_mscale are
all well managed in a running top. They were, however,
each vulnerable to tampering via the rcfile. So rather
than continually addressing the symptoms, we'll attack
the root cause just once at startup in the next patch.

Reference(s):
. original qualys patch
0099-top-Check-graph_cpus-graph_mems-and-summ_mscale.patch
commit cd8ba5670e

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2018-05-18 00:00:00 -05:00 committed by Craig Small
parent e531c78140
commit d1fbc5fbd4

View File

@ -5456,13 +5456,13 @@ static void summary_hlp (CPU_t *cpu, const char *pfx) {
/* display some kinda' cpu state percentages /* display some kinda' cpu state percentages
(who or what is explained by the passed prefix) */ (who or what is explained by the passed prefix) */
static const struct { if (Curwin->rc.graph_cpus) {
const char *user, *syst, *type; static struct {
} gtab[] = { const char *user, *syst, *type;
{ "%-.*s~7", "%-.*s~8", Graph_bars }, } gtab[] = {
{ "%-.*s~4", "%-.*s~6", Graph_blks } { "%-.*s~7", "%-.*s~8", Graph_bars },
}; { "%-.*s~4", "%-.*s~6", Graph_blks }
if (Curwin->rc.graph_cpus >= 1 && (size_t)Curwin->rc.graph_cpus <= sizeof(gtab) / sizeof(gtab[0])) { };
char user[SMLBUFSIZ], syst[SMLBUFSIZ], dual[MEDBUFSIZ]; char user[SMLBUFSIZ], syst[SMLBUFSIZ], dual[MEDBUFSIZ];
int ix = Curwin->rc.graph_cpus - 1; int ix = Curwin->rc.graph_cpus - 1;
float pct_user = (float)(u_frme + n_frme) * scale, float pct_user = (float)(u_frme + n_frme) * scale,
@ -5577,33 +5577,32 @@ numa_nope:
} // end: View_STATES } // end: View_STATES
// Display Memory and Swap stats // Display Memory and Swap stats
static struct { if (isROOM(View_MEMORY, 2)) {
float div;
const char *fmts;
const char *label;
} scaletab[] = {
{ 1, "%.0f ", NULL }, // kibibytes
#ifdef BOOST_MEMORY
{ 1024.0, "%#.3f ", NULL }, // mebibytes
{ 1024.0*1024, "%#.3f ", NULL }, // gibibytes
{ 1024.0*1024*1024, "%#.3f ", NULL }, // tebibytes
{ 1024.0*1024*1024*1024, "%#.3f ", NULL }, // pebibytes
{ 1024.0*1024*1024*1024*1024, "%#.3f ", NULL } // exbibytes
#else
{ 1024.0, "%#.1f ", NULL }, // mebibytes
{ 1024.0*1024, "%#.1f ", NULL }, // gibibytes
{ 1024.0*1024*1024, "%#.1f ", NULL }, // tebibytes
{ 1024.0*1024*1024*1024, "%#.1f ", NULL }, // pebibytes
{ 1024.0*1024*1024*1024*1024, "%#.1f ", NULL } // exbibytes
#endif
};
if (isROOM(View_MEMORY, 2) &&
Rc.summ_mscale >= 0 && (size_t)Rc.summ_mscale < sizeof(scaletab) / sizeof(scaletab[0])) {
#define bfT(n) buftab[n].buf #define bfT(n) buftab[n].buf
#define scT(e) scaletab[Rc.summ_mscale]. e #define scT(e) scaletab[Rc.summ_mscale]. e
#define mkM(x) (float)kb_main_ ## x / scT(div) #define mkM(x) (float)kb_main_ ## x / scT(div)
#define mkS(x) (float)kb_swap_ ## x / scT(div) #define mkS(x) (float)kb_swap_ ## x / scT(div)
#define prT(b,z) { if (9 < snprintf(b, 10, scT(fmts), z)) b[8] = '+'; } #define prT(b,z) { if (9 < snprintf(b, 10, scT(fmts), z)) b[8] = '+'; }
static struct {
float div;
const char *fmts;
const char *label;
} scaletab[] = {
{ 1, "%.0f ", NULL }, // kibibytes
#ifdef BOOST_MEMORY
{ 1024.0, "%#.3f ", NULL }, // mebibytes
{ 1024.0*1024, "%#.3f ", NULL }, // gibibytes
{ 1024.0*1024*1024, "%#.3f ", NULL }, // tebibytes
{ 1024.0*1024*1024*1024, "%#.3f ", NULL }, // pebibytes
{ 1024.0*1024*1024*1024*1024, "%#.3f ", NULL } // exbibytes
#else
{ 1024.0, "%#.1f ", NULL }, // mebibytes
{ 1024.0*1024, "%#.1f ", NULL }, // gibibytes
{ 1024.0*1024*1024, "%#.1f ", NULL }, // tebibytes
{ 1024.0*1024*1024*1024, "%#.1f ", NULL }, // pebibytes
{ 1024.0*1024*1024*1024*1024, "%#.1f ", NULL } // exbibytes
#endif
};
struct { // 0123456789 struct { // 0123456789
// snprintf contents of each buf (after SK_Kb): 'nnnn.nnn 0' // snprintf contents of each buf (after SK_Kb): 'nnnn.nnn 0'
// and prT macro might replace space at buf[8] with: ------> + // and prT macro might replace space at buf[8] with: ------> +
@ -5619,13 +5618,13 @@ numa_nope:
scaletab[5].label = N_txt(AMT_exxabyte_txt); scaletab[5].label = N_txt(AMT_exxabyte_txt);
} }
static const struct { if (w->rc.graph_mems) {
const char *used, *misc, *swap, *type; static struct {
} gtab[] = { const char *used, *misc, *swap, *type;
{ "%-.*s~7", "%-.*s~8", "%-.*s~8", Graph_bars }, } gtab[] = {
{ "%-.*s~4", "%-.*s~6", "%-.*s~6", Graph_blks } { "%-.*s~7", "%-.*s~8", "%-.*s~8", Graph_bars },
}; { "%-.*s~4", "%-.*s~6", "%-.*s~6", Graph_blks }
if (w->rc.graph_mems >= 1 && (size_t)w->rc.graph_mems <= sizeof(gtab) / sizeof(gtab[0])) { };
char used[SMLBUFSIZ], util[SMLBUFSIZ], dual[MEDBUFSIZ]; char used[SMLBUFSIZ], util[SMLBUFSIZ], dual[MEDBUFSIZ];
float pct_used, pct_misc, pct_swap; float pct_used, pct_misc, pct_swap;
int ix, num_used, num_misc; int ix, num_used, num_misc;