~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/watchdog/src/watchdog-test.c

Version: ~ [ linux-5.14-rc3 ] ~ [ linux-5.13.5 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.53 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.135 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.198 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.240 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.276 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.276 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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>
 10 #include <signal.h>
 11 #include <sys/ioctl.h>
 12 #include <linux/types.h>
 13 #include <linux/watchdog.h>
 14 
 15 int 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  */
 22 static void keep_alive(void)
 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  */
 33 
 34 static void term(int sig)
 35 {
 36     close(fd);
 37     fprintf(stderr, "Stopping watchdog ticks...\n");
 38     exit(0);
 39 }
 40 
 41 int main(int argc, char *argv[])
 42 {
 43     int flags;
 44 
 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)) {
 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;
 71         }
 72     } else {
 73         fprintf(stderr, "Watchdog Ticking Away!\n");
 74         fflush(stderr);
 75     }
 76 
 77     signal(SIGINT, term);
 78 
 79     while(1) {
 80         keep_alive();
 81         sleep(1);
 82     }
 83 end:
 84     close(fd);
 85     return 0;
 86 }
 87 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp