cregit-Linux how code gets into the kernel

Release 4.7 Documentation/watchdog/src/watchdog-test.c

/*
 * Watchdog Driver Test Program
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/watchdog.h>


int fd;

/*
 * This function simply sends an IOCTL to the driver, which in turn ticks
 * the PC Watchdog card to reset its internal timer so it doesn't trigger
 * a computer reset.
 */

static void keep_alive(void) { int dummy; ioctl(fd, WDIOC_KEEPALIVE, &dummy); }

Contributors

PersonTokensPropCommitsCommitProp
randy dunlaprandy dunlap2095.24%150.00%
ladinu chandrasingheladinu chandrasinghe14.76%150.00%
Total21100.00%2100.00%

/* * The main program. Run the program with "-d" to disable the card, * or "-e" to enable the card. */
static void term(int sig) { close(fd); fprintf(stderr, "Stopping watchdog ticks...\n"); exit(0); }

Contributors

PersonTokensPropCommitsCommitProp
devendra nagadevendra naga2596.15%150.00%
randy dunlaprandy dunlap13.85%150.00%
Total26100.00%2100.00%


int main(int argc, char *argv[]) { int flags; unsigned int ping_rate = 1; fd = open("/dev/watchdog", O_WRONLY); if (fd == -1) { fprintf(stderr, "Watchdog device not enabled.\n"); fflush(stderr); exit(-1); } if (argc > 1) { if (!strncasecmp(argv[1], "-d", 2)) { flags = WDIOS_DISABLECARD; ioctl(fd, WDIOC_SETOPTIONS, &flags); fprintf(stderr, "Watchdog card disabled.\n"); fflush(stderr); goto end; } else if (!strncasecmp(argv[1], "-e", 2)) { flags = WDIOS_ENABLECARD; ioctl(fd, WDIOC_SETOPTIONS, &flags); fprintf(stderr, "Watchdog card enabled.\n"); fflush(stderr); goto end; } else if (!strncasecmp(argv[1], "-t", 2) && argv[2]) { flags = atoi(argv[2]); ioctl(fd, WDIOC_SETTIMEOUT, &flags); fprintf(stderr, "Watchdog timeout set to %u seconds.\n", flags); fflush(stderr); goto end; } else if (!strncasecmp(argv[1], "-p", 2) && argv[2]) { ping_rate = strtoul(argv[2], NULL, 0); fprintf(stderr, "Watchdog ping rate set to %u seconds.\n", ping_rate); fflush(stderr); } else { fprintf(stderr, "-d to disable, -e to enable, -t <n> to set " \ "the timeout,\n-p <n> to set the ping rate, and \n"); fprintf(stderr, "run by itself to tick the card.\n"); fflush(stderr); goto end; } } fprintf(stderr, "Watchdog Ticking Away!\n"); fflush(stderr); signal(SIGINT, term); while(1) { keep_alive(); sleep(ping_rate); } end: close(fd); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
randy dunlaprandy dunlap17852.35%120.00%
timur tabitimur tabi12135.59%120.00%
devendra nagadevendra naga267.65%240.00%
james hoganjames hogan154.41%120.00%
Total340100.00%5100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
randy dunlaprandy dunlap22954.52%228.57%
timur tabitimur tabi12128.81%114.29%
devendra nagadevendra naga5412.86%228.57%
james hoganjames hogan153.57%114.29%
ladinu chandrasingheladinu chandrasinghe10.24%114.29%
Total420100.00%7100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}