Skip to content

Commit

Permalink
selftests: watchdog: Validate optional file argument
Browse files Browse the repository at this point in the history
The newly added optional file argument does not validate if the
file is indeed a watchdog, e.g.:

./watchdog-test  -f /dev/zero
Watchdog Ticking Away!

Fix it by confirming that the WDIOC_GETSUPPORT ioctl succeeds.

Fixes: a4864a3 ("selftests: watchdog: Add optional file argument")
Reported-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: George G. Davis <george_davis@mentor.com>
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
  • Loading branch information
George G. Davis authored and Shuah Khan committed Oct 2, 2019
1 parent 852c8cb commit 8f9577e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tools/testing/selftests/watchdog/watchdog-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ int main(int argc, char *argv[])
int c;
int oneshot = 0;
char *file = "/dev/watchdog";
struct watchdog_info info;

setbuf(stdout, NULL);

Expand All @@ -118,6 +119,16 @@ int main(int argc, char *argv[])
exit(-1);
}

/*
* Validate that `file` is a watchdog device
*/
ret = ioctl(fd, WDIOC_GETSUPPORT, &info);
if (ret) {
printf("WDIOC_GETSUPPORT error '%s'\n", strerror(errno));
close(fd);
exit(ret);
}

optind = 0;

while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
Expand Down

0 comments on commit 8f9577e

Please sign in to comment.