Linux 4.2-rc8
[deliverable/linux.git] / Documentation / watchdog / src / watchdog-test.c
CommitLineData
56fb9e53
RD
1/*
2 * Watchdog Driver Test Program
3 */
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8#include <unistd.h>
9#include <fcntl.h>
cad19fa6 10#include <signal.h>
56fb9e53
RD
11#include <sys/ioctl.h>
12#include <linux/types.h>
13#include <linux/watchdog.h>
14
15int fd;
16
17/*
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.
21 */
b7ed698c 22static void keep_alive(void)
56fb9e53
RD
23{
24 int dummy;
25
26 ioctl(fd, WDIOC_KEEPALIVE, &dummy);
27}
28
29/*
30 * The main program. Run the program with "-d" to disable the card,
31 * or "-e" to enable the card.
32 */
cad19fa6 33
4b1c2f41 34static void term(int sig)
cad19fa6
DN
35{
36 close(fd);
37 fprintf(stderr, "Stopping watchdog ticks...\n");
38 exit(0);
39}
40
56fb9e53
RD
41int main(int argc, char *argv[])
42{
dfc33383
JH
43 int flags;
44
56fb9e53
RD
45 fd = open("/dev/watchdog", O_WRONLY);
46
47 if (fd == -1) {
48 fprintf(stderr, "Watchdog device not enabled.\n");
49 fflush(stderr);
50 exit(-1);
51 }
52
53 if (argc > 1) {
54 if (!strncasecmp(argv[1], "-d", 2)) {
dfc33383
JH
55 flags = WDIOS_DISABLECARD;
56 ioctl(fd, WDIOC_SETOPTIONS, &flags);
56fb9e53
RD
57 fprintf(stderr, "Watchdog card disabled.\n");
58 fflush(stderr);
3c2a6186 59 goto end;
56fb9e53 60 } else if (!strncasecmp(argv[1], "-e", 2)) {
dfc33383
JH
61 flags = WDIOS_ENABLECARD;
62 ioctl(fd, WDIOC_SETOPTIONS, &flags);
56fb9e53
RD
63 fprintf(stderr, "Watchdog card enabled.\n");
64 fflush(stderr);
3c2a6186 65 goto end;
56fb9e53
RD
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);
3c2a6186 70 goto end;
56fb9e53
RD
71 }
72 } else {
73 fprintf(stderr, "Watchdog Ticking Away!\n");
74 fflush(stderr);
75 }
76
cad19fa6
DN
77 signal(SIGINT, term);
78
56fb9e53
RD
79 while(1) {
80 keep_alive();
81 sleep(1);
82 }
3c2a6186
DN
83end:
84 close(fd);
85 return 0;
56fb9e53 86}
This page took 0.624096 seconds and 5 git commands to generate.