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

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

Version: ~ [ linux-5.15-rc1 ] ~ [ linux-5.14.5 ] ~ [ linux-5.13.18 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.66 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.147 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.206 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.246 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.282 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.283 ] ~ [ 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     unsigned int ping_rate = 1;
 45 
 46     fd = open("/dev/watchdog", O_WRONLY);
 47 
 48     if (fd == -1) {
 49         fprintf(stderr, "Watchdog device not enabled.\n");
 50         fflush(stderr);
 51         exit(-1);
 52     }
 53 
 54     if (argc > 1) {
 55         if (!strncasecmp(argv[1], "-d", 2)) {
 56             flags = WDIOS_DISABLECARD;
 57             ioctl(fd, WDIOC_SETOPTIONS, &flags);
 58             fprintf(stderr, "Watchdog card disabled.\n");
 59             fflush(stderr);
 60             goto end;
 61         } else if (!strncasecmp(argv[1], "-e", 2)) {
 62             flags = WDIOS_ENABLECARD;
 63             ioctl(fd, WDIOC_SETOPTIONS, &flags);
 64             fprintf(stderr, "Watchdog card enabled.\n");
 65             fflush(stderr);
 66             goto end;
 67         } else if (!strncasecmp(argv[1], "-t", 2) && argv[2]) {
 68             flags = atoi(argv[2]);
 69             ioctl(fd, WDIOC_SETTIMEOUT, &flags);
 70             fprintf(stderr, "Watchdog timeout set to %u seconds.\n", flags);
 71             fflush(stderr);
 72             goto end;
 73         } else if (!strncasecmp(argv[1], "-p", 2) && argv[2]) {
 74             ping_rate = strtoul(argv[2], NULL, 0);
 75             fprintf(stderr, "Watchdog ping rate set to %u seconds.\n", ping_rate);
 76             fflush(stderr);
 77         } else {
 78             fprintf(stderr, "-d to disable, -e to enable, -t <n> to set " \
 79                 "the timeout,\n-p <n> to set the ping rate, and \n");
 80             fprintf(stderr, "run by itself to tick the card.\n");
 81             fflush(stderr);
 82             goto end;
 83         }
 84     }
 85 
 86     fprintf(stderr, "Watchdog Ticking Away!\n");
 87     fflush(stderr);
 88 
 89     signal(SIGINT, term);
 90 
 91     while(1) {
 92         keep_alive();
 93         sleep(ping_rate);
 94     }
 95 end:
 96     close(fd);
 97     return 0;
 98 }
 99 

~ [ 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