selftests: watchdog: fix message when /dev/watchdog open fails
authorShuah Khan (Samsung OSG) <shuah@kernel.org>
Wed, 26 Sep 2018 19:07:11 +0000 (13:07 -0600)
committerShuah Khan (Samsung OSG) <shuah@kernel.org>
Wed, 24 Oct 2018 20:49:36 +0000 (14:49 -0600)
When /dev/watchdog open fails, watchdog exits with "watchdog not enabled"
message. This is incorrect when open fails due to insufficient privilege.

Fix message to clearly state the reason when open fails with EACCESS when
a non-root user runs it.

Signed-off-by: Shuah Khan (Samsung OSG) <shuah@kernel.org>
tools/testing/selftests/watchdog/watchdog-test.c

index 6e290874b70e212e72c0f337bbdb597036d00d48..e029e2017280f2f1f2fc82b5be3c7fbc77f8bea9 100644 (file)
@@ -89,7 +89,13 @@ int main(int argc, char *argv[])
        fd = open("/dev/watchdog", O_WRONLY);
 
        if (fd == -1) {
-               printf("Watchdog device not enabled.\n");
+               if (errno == ENOENT)
+                       printf("Watchdog device not enabled.\n");
+               else if (errno == EACCES)
+                       printf("Run watchdog as root.\n");
+               else
+                       printf("Watchdog device open failed %s\n",
+                               strerror(errno));
                exit(-1);
        }