diff mbox series

[09/12] main: Improve get_pir() error message

Message ID 20210802054112.461728-10-jniethe5@gmail.com
State Superseded
Headers show
Series P10 HTM Support | expand

Commit Message

Jordan Niethe Aug. 2, 2021, 5:41 a.m. UTC
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@gmail.com>
---
 src/main.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff mbox series

Patch

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) {