From ea10995f4d62e6f6adbbc9ec16dd84bb6386618b Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Fri, 9 Oct 2020 09:51:40 +0200 Subject: [PATCH] cpumf/chcpumf.c: Fix version and help printout when CPUMF not installed. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit chcpumf does not print out version (option -v) or help text (option -h) when the CPU Measurement Sampling facility is not installed. This was different up to and including release 4.10. Fix this and hounour option -v and option -h even when the sampling facility is not installed. Signed-off-by: Thomas Richter Reviewed-by: Sumanth Korikkar Signed-off-by: Jan Höppner --- cpumf/chcpumf.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cpumf/chcpumf.c b/cpumf/chcpumf.c index 1f9f0ed8..2aaf39d8 100644 --- a/cpumf/chcpumf.c +++ b/cpumf/chcpumf.c @@ -60,10 +60,6 @@ static const struct util_prg prg = { } }; -/* Parse tool parameters. Fill in global variables keep_case, buffersize and - * command according to parameters. Return VMCP_OK on success, VMCP_OPT - * in case of parameter errors. In case of --help or --version, print - * respective text to stdout and exit. */ static long parse_buffersize(char *string) { char *suffix; @@ -91,6 +87,7 @@ static long parse_buffersize(char *string) static int read_sfb(unsigned long *min, unsigned long *max) { + unsigned long cur_min_sdb, cur_max_sdb; int rc = EXIT_SUCCESS; FILE *fp; @@ -99,9 +96,14 @@ static int read_sfb(unsigned long *min, unsigned long *max) linux_error(PERF_SFB_SIZE); return EXIT_FAILURE; } - if (fscanf(fp, "%ld,%ld", min, max) != 2) { + if (fscanf(fp, "%ld,%ld", &cur_min_sdb, &cur_max_sdb) != 2) { fprintf(stderr, "Error: Can not parse file " PERF_SFB_SIZE); rc = EXIT_FAILURE; + } else { + if (*min == 0) + *min = cur_min_sdb; + if (*max == 0) + *max = cur_max_sdb; } fclose(fp); return rc; @@ -196,6 +198,7 @@ int main(int argc, char **argv) util_prg_init(&prg); util_opt_init(opt_vec, NULL); + parse_args(argc, argv); if (stat(PERF_PATH PERF_SF, &sbuf) != 0) { fprintf(stderr, "No CPU-measurement sampling facility detected\n"); @@ -203,8 +206,6 @@ int main(int argc, char **argv) } if (read_sfb(&min_sdb, &max_sdb)) return ret; - /* Overwrite min_sdb and/or max_sdb */ - parse_args(argc, argv); if (min_sdb >= max_sdb) { fprintf(stderr, "The specified maximum must be greater " "than the minimum\n");