[Pdbg] [PATCH 09/12] main: Improve get_pir() error message
Jordan Niethe
jniethe5 at gmail.com
Mon Aug 2 15:41:09 AEST 2021
The error message from get_pir() can be misleading if not ran as root.
That is you may be using a valid linux CPU number but simply lack the
required permissions. Indicate this possiblity in the error message.
Signed-off-by: Jordan Niethe <jniethe5 at gmail.com>
---
src/main.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/main.c b/src/main.c
index 4c117f68bab5..70e7b05b4321 100644
--- a/src/main.c
+++ b/src/main.c
@@ -178,8 +178,15 @@ int get_pir(int linux_cpu)
file = fopen(filename, "r");
if (!file) {
- PR_ERROR("Invalid Linux CPU number %" PRIi32 "\n", linux_cpu);
- goto out2;
+ switch (errno) {
+ case ENOENT:
+ PR_ERROR("Invalid Linux CPU number %" PRIi32 "\n", linux_cpu);
+ goto out2;
+ case EACCES:
+ default:
+ PR_ERROR("Can't access %s. Try running as root\n", filename);
+ goto out2;
+ }
}
if(fscanf(file, "%" PRIx32 "\n", &pir) != 1) {
--
2.25.1
More information about the Pdbg
mailing list