selftests: watchdog: fix message when /dev/watchdog open fails

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>
This commit is contained in:
Shuah Khan (Samsung OSG) 2018-09-26 13:07:11 -06:00
parent 8ffade754b
commit 9a244229a4
1 changed files with 7 additions and 1 deletions

View File

@ -89,7 +89,13 @@ int main(int argc, char *argv[])
fd = open("/dev/watchdog", O_WRONLY);
if (fd == -1) {
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);
}