From 886476a20736d34999fda331962f809e80618a77 Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Wed, 11 Nov 2020 17:24:07 +0100 Subject: [PATCH] cpumf/chcpumf.c: Print proper error message on non-root invocation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit chcpumf must be executed as root. A non-root user sees this error message: [tester@t35lp46 ~]$ chcpumf -m 1000 Error: /sys/module/kernel/parameters/cpum_sfb_size: Permission denied [tester@t35lp46 ~]$ Enhance the error message and be clear about the root cause: [tester@t35lp46 ~]$ chcpumf-new -m 1000 Error: Must run as root [tester@t35lp46 ~]$ Signed-off-by: Thomas Richter Acked-by: Sumanth Korikkar Signed-off-by: Jan Höppner --- cpumf/chcpumf.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cpumf/chcpumf.c b/cpumf/chcpumf.c index 2aaf39d8..3f7056aa 100644 --- a/cpumf/chcpumf.c +++ b/cpumf/chcpumf.c @@ -91,13 +91,18 @@ static int read_sfb(unsigned long *min, unsigned long *max) int rc = EXIT_SUCCESS; FILE *fp; + if (geteuid()) { + fprintf(stderr, "Error: Must run as root\n"); + return EXIT_FAILURE; + } fp = fopen(PERF_SFB_SIZE, "r"); if (fp == NULL) { linux_error(PERF_SFB_SIZE); return EXIT_FAILURE; } if (fscanf(fp, "%ld,%ld", &cur_min_sdb, &cur_max_sdb) != 2) { - fprintf(stderr, "Error: Can not parse file " PERF_SFB_SIZE); + fprintf(stderr, "Error: Can not parse file " PERF_SFB_SIZE + "\n"); rc = EXIT_FAILURE; } else { if (*min == 0)