Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[WATCHDOG] Documentation/watchdog update

Documentation/watchdog/:
Expose example and tool source files in the Documentation/ directory in
their own files instead of being buried (almost hidden) in readme/txt files.

This will make them more visible/usable to users who may need
to use them, to developers who may need to test with them, and
to janitors who would update them if they were more visible.

Also, if any of these possibly should not be in the kernel tree at
all, it will be clearer that they are here and we can discuss if
they should be removed.

Signed-off-by: Randy Dunlap <rdunlap@xenotime.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Signed-off-by: Andrew Morton <akpm@osdl.org>

authored by

Randy Dunlap and committed by
Wim Van Sebroeck
56fb9e53 dfc7bd9c

+87 -109
+2 -71
Documentation/watchdog/pcwd-watchdog.txt
··· 22 22 to run the program with an "&" to run it in the background!) 23 23 24 24 If you want to write a program to be compatible with the PC Watchdog 25 - driver, simply do the following: 25 + driver, simply use of modify the watchdog test program: 26 + Documentation/watchdog/src/watchdog-test.c 26 27 27 - -- Snippet of code -- 28 - /* 29 - * Watchdog Driver Test Program 30 - */ 31 - 32 - #include <stdio.h> 33 - #include <stdlib.h> 34 - #include <string.h> 35 - #include <unistd.h> 36 - #include <fcntl.h> 37 - #include <sys/ioctl.h> 38 - #include <linux/types.h> 39 - #include <linux/watchdog.h> 40 - 41 - int fd; 42 - 43 - /* 44 - * This function simply sends an IOCTL to the driver, which in turn ticks 45 - * the PC Watchdog card to reset its internal timer so it doesn't trigger 46 - * a computer reset. 47 - */ 48 - void keep_alive(void) 49 - { 50 - int dummy; 51 - 52 - ioctl(fd, WDIOC_KEEPALIVE, &dummy); 53 - } 54 - 55 - /* 56 - * The main program. Run the program with "-d" to disable the card, 57 - * or "-e" to enable the card. 58 - */ 59 - int main(int argc, char *argv[]) 60 - { 61 - fd = open("/dev/watchdog", O_WRONLY); 62 - 63 - if (fd == -1) { 64 - fprintf(stderr, "Watchdog device not enabled.\n"); 65 - fflush(stderr); 66 - exit(-1); 67 - } 68 - 69 - if (argc > 1) { 70 - if (!strncasecmp(argv[1], "-d", 2)) { 71 - ioctl(fd, WDIOC_SETOPTIONS, WDIOS_DISABLECARD); 72 - fprintf(stderr, "Watchdog card disabled.\n"); 73 - fflush(stderr); 74 - exit(0); 75 - } else if (!strncasecmp(argv[1], "-e", 2)) { 76 - ioctl(fd, WDIOC_SETOPTIONS, WDIOS_ENABLECARD); 77 - fprintf(stderr, "Watchdog card enabled.\n"); 78 - fflush(stderr); 79 - exit(0); 80 - } else { 81 - fprintf(stderr, "-d to disable, -e to enable.\n"); 82 - fprintf(stderr, "run by itself to tick the card.\n"); 83 - fflush(stderr); 84 - exit(0); 85 - } 86 - } else { 87 - fprintf(stderr, "Watchdog Ticking Away!\n"); 88 - fflush(stderr); 89 - } 90 - 91 - while(1) { 92 - keep_alive(); 93 - sleep(1); 94 - } 95 - } 96 - -- End snippet -- 97 28 98 29 Other IOCTL functions include: 99 30
+15
Documentation/watchdog/src/watchdog-simple.c
··· 1 + #include <stdlib.h> 2 + #include <fcntl.h> 3 + 4 + int main(int argc, const char *argv[]) { 5 + int fd = open("/dev/watchdog", O_WRONLY); 6 + if (fd == -1) { 7 + perror("watchdog"); 8 + exit(1); 9 + } 10 + while (1) { 11 + write(fd, "\0", 1); 12 + fsync(fd); 13 + sleep(10); 14 + } 15 + }
+68
Documentation/watchdog/src/watchdog-test.c
··· 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 <sys/ioctl.h> 11 + #include <linux/types.h> 12 + #include <linux/watchdog.h> 13 + 14 + int fd; 15 + 16 + /* 17 + * This function simply sends an IOCTL to the driver, which in turn ticks 18 + * the PC Watchdog card to reset its internal timer so it doesn't trigger 19 + * a computer reset. 20 + */ 21 + void keep_alive(void) 22 + { 23 + int dummy; 24 + 25 + ioctl(fd, WDIOC_KEEPALIVE, &dummy); 26 + } 27 + 28 + /* 29 + * The main program. Run the program with "-d" to disable the card, 30 + * or "-e" to enable the card. 31 + */ 32 + int main(int argc, char *argv[]) 33 + { 34 + fd = open("/dev/watchdog", O_WRONLY); 35 + 36 + if (fd == -1) { 37 + fprintf(stderr, "Watchdog device not enabled.\n"); 38 + fflush(stderr); 39 + exit(-1); 40 + } 41 + 42 + if (argc > 1) { 43 + if (!strncasecmp(argv[1], "-d", 2)) { 44 + ioctl(fd, WDIOC_SETOPTIONS, WDIOS_DISABLECARD); 45 + fprintf(stderr, "Watchdog card disabled.\n"); 46 + fflush(stderr); 47 + exit(0); 48 + } else if (!strncasecmp(argv[1], "-e", 2)) { 49 + ioctl(fd, WDIOC_SETOPTIONS, WDIOS_ENABLECARD); 50 + fprintf(stderr, "Watchdog card enabled.\n"); 51 + fflush(stderr); 52 + exit(0); 53 + } else { 54 + fprintf(stderr, "-d to disable, -e to enable.\n"); 55 + fprintf(stderr, "run by itself to tick the card.\n"); 56 + fflush(stderr); 57 + exit(0); 58 + } 59 + } else { 60 + fprintf(stderr, "Watchdog Ticking Away!\n"); 61 + fflush(stderr); 62 + } 63 + 64 + while(1) { 65 + keep_alive(); 66 + sleep(1); 67 + } 68 + }
+1 -16
Documentation/watchdog/watchdog-api.txt
··· 34 34 the watchdog is pinged within a certain time, this time is called the 35 35 timeout or margin. The simplest way to ping the watchdog is to write 36 36 some data to the device. So a very simple watchdog daemon would look 37 - like this: 38 - 39 - #include <stdlib.h> 40 - #include <fcntl.h> 41 - 42 - int main(int argc, const char *argv[]) { 43 - int fd=open("/dev/watchdog",O_WRONLY); 44 - if (fd==-1) { 45 - perror("watchdog"); 46 - exit(1); 47 - } 48 - while(1) { 49 - write(fd, "\0", 1); 50 - sleep(10); 51 - } 52 - } 37 + like this source file: see Documentation/watchdog/src/watchdog-simple.c 53 38 54 39 A more advanced driver could for example check that a HTTP server is 55 40 still responding before doing the write call to ping the watchdog.
+1 -22
Documentation/watchdog/watchdog.txt
··· 65 65 Minor numbers are however allocated for it. 66 66 67 67 68 - Example Watchdog Driver 69 - ----------------------- 70 - 71 - #include <stdio.h> 72 - #include <unistd.h> 73 - #include <fcntl.h> 74 - 75 - int main(int argc, const char *argv[]) 76 - { 77 - int fd=open("/dev/watchdog",O_WRONLY); 78 - if(fd==-1) 79 - { 80 - perror("watchdog"); 81 - exit(1); 82 - } 83 - while(1) 84 - { 85 - write(fd,"\0",1); 86 - fsync(fd); 87 - sleep(10); 88 - } 89 - } 68 + Example Watchdog Driver: see Documentation/watchdog/src/watchdog-simple.c 90 69 91 70 92 71 Contact Information