Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[linux/fpc-iii.git] / Documentation / watchdog / src / watchdog-test.c
blob3da822967ee0e13d1a2dbcd88d2d75f5a4aca370
1 /*
2 * Watchdog Driver Test Program
3 */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <unistd.h>
9 #include <fcntl.h>
10 #include <signal.h>
11 #include <sys/ioctl.h>
12 #include <linux/types.h>
13 #include <linux/watchdog.h>
15 int fd;
18 * This function simply sends an IOCTL to the driver, which in turn ticks
19 * the PC Watchdog card to reset its internal timer so it doesn't trigger
20 * a computer reset.
22 static void keep_alive(void)
24 int dummy;
26 ioctl(fd, WDIOC_KEEPALIVE, &dummy);
30 * The main program. Run the program with "-d" to disable the card,
31 * or "-e" to enable the card.
34 static void term(int sig)
36 close(fd);
37 fprintf(stderr, "Stopping watchdog ticks...\n");
38 exit(0);
41 int main(int argc, char *argv[])
43 int flags;
45 fd = open("/dev/watchdog", O_WRONLY);
47 if (fd == -1) {
48 fprintf(stderr, "Watchdog device not enabled.\n");
49 fflush(stderr);
50 exit(-1);
53 if (argc > 1) {
54 if (!strncasecmp(argv[1], "-d", 2)) {
55 flags = WDIOS_DISABLECARD;
56 ioctl(fd, WDIOC_SETOPTIONS, &flags);
57 fprintf(stderr, "Watchdog card disabled.\n");
58 fflush(stderr);
59 goto end;
60 } else if (!strncasecmp(argv[1], "-e", 2)) {
61 flags = WDIOS_ENABLECARD;
62 ioctl(fd, WDIOC_SETOPTIONS, &flags);
63 fprintf(stderr, "Watchdog card enabled.\n");
64 fflush(stderr);
65 goto end;
66 } else {
67 fprintf(stderr, "-d to disable, -e to enable.\n");
68 fprintf(stderr, "run by itself to tick the card.\n");
69 fflush(stderr);
70 goto end;
72 } else {
73 fprintf(stderr, "Watchdog Ticking Away!\n");
74 fflush(stderr);
77 signal(SIGINT, term);
79 while(1) {
80 keep_alive();
81 sleep(1);
83 end:
84 close(fd);
85 return 0;