commit 2ab1cf5d1e547f991c64dde97749a666c045fc25
Author: Nathan Scott <nathans@redhat.com>
Date: Tue Oct 29 02:28:10 2019 +1100
pcp-atopsar: fix mishandling of some command line arguments
Cleanup several aspects of command line handling in pcp-atopsar,
and resolve a reported bug where the samples argument was not
honoured due to shadowing of a same-named variable with atop.
Resolves Red Hat BZ 1764748.
diff --git a/qa/785 b/qa/785
index 89e564d2a..5f637367b 100755
--- a/qa/785
+++ b/qa/785
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/sh
# PCP QA Test No. 785
# Basic checkout of the pcp-atopsar(1) utility.
#
@@ -51,10 +51,11 @@ echo; echo == Checking sample count and interval
export PCP_ARCHIVE=$here/archives/pcp-atop
pcp -z atopsar -m 2 3 > $tmp.mem1
pcp -z -t 2 -s 3 atopsar -m > $tmp.mem2
-unset PCP_ARCHIVE
test -s $tmp.mem1 || echo "Unexpected empty file 1"
test -s $tmp.mem2 || echo "Unexpected empty file 2"
diff $tmp.mem1 $tmp.mem2 && echo OK
+pcp -z atopsar -m 1 2 | _filter
+unset PCP_ARCHIVE
echo; echo == Check handling of missing values
pcp atopsar -r archives/pcp-vmstat
diff --git a/qa/785.out b/qa/785.out
index 32207712c..e38b7e743 100644
--- a/qa/785.out
+++ b/qa/785.out
@@ -89,6 +89,13 @@ HOST-SUMMARY-LINE
== Checking sample count and interval
OK
+HOST-SUMMARY-LINE
+
+-------------------------- analysis date: 2015/09/25 --------------------------
+
+11:03:21 memtotal memfree buffers cached dirty slabmem swptotal swpfree _mem_
+11:03:21 3849M 196M 275M 1553M 0M 357M 13661M 13652M
+
== Check handling of missing values
pcp-atopsar: no per-processor values available
pcp-atopsar: no per-interface values available
diff --git a/src/pcp/atop/atop.c b/src/pcp/atop/atop.c
index cf6ec821f..fbfc19c89 100644
--- a/src/pcp/atop/atop.c
+++ b/src/pcp/atop/atop.c
@@ -173,7 +173,7 @@ struct visualize vis = {generic_samp, generic_error,
** argument values
*/
static char awaittrigger; /* boolean: awaiting trigger */
-static unsigned int nsamples = 0xffffffff;
+unsigned int nsamples = 0xffffffff;
static char midnightflag;
/*
@@ -294,7 +294,6 @@ main(int argc, char *argv[])
if ( (p = getenv("HOME")) )
{
pmsprintf(path, sizeof(path), "%s/.atoprc", p);
- path[sizeof(path)-1] = '\0';
readrc(path, 0);
}
@@ -424,7 +423,7 @@ main(int argc, char *argv[])
if (opts.narchives > 0)
rawreadflag++;
- __pmEndOptions(&opts);
+ close_options(&opts);
if (opts.errors)
prusage(pmGetProgname(), &opts);
diff --git a/src/pcp/atop/atop.h b/src/pcp/atop/atop.h
index 45f09dc76..c10e5e13a 100644
--- a/src/pcp/atop/atop.h
+++ b/src/pcp/atop/atop.h
@@ -175,6 +175,7 @@ int contcompar(const void *, const void *);
count_t subcount(count_t, count_t);
void setup_options(struct pmOptions *, char **, char *);
+void close_options(struct pmOptions *);
void rawread(struct pmOptions *);
void rawfolio(struct pmOptions *);
void rawarchive(struct pmOptions *, const char *);
diff --git a/src/pcp/atop/atopsar.c b/src/pcp/atop/atopsar.c
index 47324e757..4a61c8dc5 100644
--- a/src/pcp/atop/atopsar.c
+++ b/src/pcp/atop/atopsar.c
@@ -48,7 +48,6 @@
/*
** miscellaneous values
*/
-static unsigned int nsamples = 9999999;
static char stampalways;
static char usemarkers;
static char allresources;
@@ -74,6 +73,7 @@ struct pridef {
char *about; /* statistics about what */
};
+extern unsigned int nsamples;
extern struct pridef pridef[]; /* table of print-functions */
extern int pricnt; /* total number of print-functions */
@@ -272,13 +272,13 @@ atopsar(int argc, char *argv[])
rawreadflag++;
}
- __pmEndOptions(&opts);
+ close_options(&opts);
if (opts.errors)
- prusage(pmGetProgname(), &opts);
+ pratopsaruse(pmGetProgname(), &opts);
- if (opts.samples)
- nsamples = opts.samples;
+ if (opts.samples > 0)
+ nsamples = opts.samples + 1;
if (opts.interval.tv_sec || opts.interval.tv_usec)
interval = opts.interval;
@@ -314,9 +314,9 @@ atopsar(int argc, char *argv[])
if (rawreadflag)
{
vis.show_samp = reportraw;
- vis.prep = prep;
- vis.next = next_prinow;
- prinow = 0;
+ vis.prep = prep;
+ vis.next = next_prinow;
+ prinow = 0;
}
else
vis.show_samp = reportlive;
diff --git a/src/pcp/atop/various.c b/src/pcp/atop/various.c
index 1a89af05d..afd418279 100644
--- a/src/pcp/atop/various.c
+++ b/src/pcp/atop/various.c
@@ -71,6 +71,15 @@ setup_options(pmOptions *opts, char **argv, char *short_options)
__pmStartOptions(opts);
}
+void
+close_options(pmOptions *opts)
+{
+ __pmEndOptions(opts);
+
+ if (opts->errors)
+ pmflush();
+}
+
/*
** Function convtime() converts a value (number of seconds since
** 1-1-1970) to an ascii-string in the format hh:mm:ss, stored in