aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/watchdog/src/watchdog-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/watchdog/src/watchdog-test.c')
-rw-r--r--Documentation/watchdog/src/watchdog-test.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/Documentation/watchdog/src/watchdog-test.c b/Documentation/watchdog/src/watchdog-test.c
index 63fdc34ceb9..73ff5cc93e0 100644
--- a/Documentation/watchdog/src/watchdog-test.c
+++ b/Documentation/watchdog/src/watchdog-test.c
@@ -7,6 +7,7 @@
7#include <string.h> 7#include <string.h>
8#include <unistd.h> 8#include <unistd.h>
9#include <fcntl.h> 9#include <fcntl.h>
10#include <signal.h>
10#include <sys/ioctl.h> 11#include <sys/ioctl.h>
11#include <linux/types.h> 12#include <linux/types.h>
12#include <linux/watchdog.h> 13#include <linux/watchdog.h>
@@ -29,6 +30,14 @@ static void keep_alive(void)
29 * The main program. Run the program with "-d" to disable the card, 30 * The main program. Run the program with "-d" to disable the card,
30 * or "-e" to enable the card. 31 * or "-e" to enable the card.
31 */ 32 */
33
34void term(int sig)
35{
36 close(fd);
37 fprintf(stderr, "Stopping watchdog ticks...\n");
38 exit(0);
39}
40
32int main(int argc, char *argv[]) 41int main(int argc, char *argv[])
33{ 42{
34 int flags; 43 int flags;
@@ -47,26 +56,31 @@ int main(int argc, char *argv[])
47 ioctl(fd, WDIOC_SETOPTIONS, &flags); 56 ioctl(fd, WDIOC_SETOPTIONS, &flags);
48 fprintf(stderr, "Watchdog card disabled.\n"); 57 fprintf(stderr, "Watchdog card disabled.\n");
49 fflush(stderr); 58 fflush(stderr);
50 exit(0); 59 goto end;
51 } else if (!strncasecmp(argv[1], "-e", 2)) { 60 } else if (!strncasecmp(argv[1], "-e", 2)) {
52 flags = WDIOS_ENABLECARD; 61 flags = WDIOS_ENABLECARD;
53 ioctl(fd, WDIOC_SETOPTIONS, &flags); 62 ioctl(fd, WDIOC_SETOPTIONS, &flags);
54 fprintf(stderr, "Watchdog card enabled.\n"); 63 fprintf(stderr, "Watchdog card enabled.\n");
55 fflush(stderr); 64 fflush(stderr);
56 exit(0); 65 goto end;
57 } else { 66 } else {
58 fprintf(stderr, "-d to disable, -e to enable.\n"); 67 fprintf(stderr, "-d to disable, -e to enable.\n");
59 fprintf(stderr, "run by itself to tick the card.\n"); 68 fprintf(stderr, "run by itself to tick the card.\n");
60 fflush(stderr); 69 fflush(stderr);
61 exit(0); 70 goto end;
62 } 71 }
63 } else { 72 } else {
64 fprintf(stderr, "Watchdog Ticking Away!\n"); 73 fprintf(stderr, "Watchdog Ticking Away!\n");
65 fflush(stderr); 74 fflush(stderr);
66 } 75 }
67 76
77 signal(SIGINT, term);
78
68 while(1) { 79 while(1) {
69 keep_alive(); 80 keep_alive();
70 sleep(1); 81 sleep(1);
71 } 82 }
83end:
84 close(fd);
85 return 0;
72} 86}